|
创建表
- proc sql; /*创建一个空表格*/
- create table country1
- (name char(20),
- capital char(20),
- population num
- )
- ;
- quit;
复制代码
- proc sql ; /*复制已有表格的表属性,创建一个空表*/
- create table a1
- like sashelp.class;
- describe table a1;
- quit;
复制代码
- proc sql outobs=10 ; /*从查询结果创建表*/
- create table a as
- select * from sashelp.class(drop=sex);
- quit;
复制代码
插入行/列
- proc sql;
- insert into countries /*用set向表格总插入行*/
- set
- name="bangladesh",
- capital="dhaka",
- population=126391060
- set
- name="japan",
- capital="tokyo",
- population=126352003
- ;
- quit;
复制代码
- proc sql; /*用values向表格总插入行*/
- insert into countries
- values("pakistan","islamabad",123060000)
- values("nigeria","lagos",99062000);
- quit;
复制代码
- proc sql; /*用select筛选符合条件的行插入表格*/
- create table newcountries
- like countries;
- insert into newcountries
- select * from countries where population ge 120000000;
- quit;
复制代码
- proc sql; /*插入列*/
- alter table countries
- add density num label="population density" format=6.2;
- update countries
- set density=population/10;
- quit;
复制代码
更新
- proc sql; /*统一更新变量的所有值*/
- update countries
- set population=population*0;
- quit;
复制代码
- proc sql ; /*有条件更新*/
- update countries
- set population = population*1.05 where name like "b%";
- update countries
- set population =population * 1.07 where name in("japan","russia");
- quit;
复制代码
删除
- proc sql ; /*删除行*/
- delete from countries where population=0;
- quit;
复制代码
- proc sql ; /*删除列*/
- alter table countries
- drop population;
- quit;
复制代码
- proc sql; /*删除表*/
- drop table countries;
- quit;
复制代码
综合应用
- proc sql ;
- create table test like sashelp.class ;
- insert into test select * from sashelp.class;
- alter table test add new num format=dollar.;
- update test set new = height* 1.2 where height<=60;
- update test set new= height * case when height <= 60 then 1.2 else 1 end;
- quit;
复制代码 |
|