设为首页收藏本站

EPS数据狗论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1761|回复: 0

SAS proc sql之:创建,插入,更新,删除

[复制链接]

30

主题

333

金钱

471

积分

入门用户

发表于 2019-10-9 15:15:14 | 显示全部楼层 |阅读模式

创建表
  1. proc sql;  /*创建一个空表格*/
  2.     create table country1
  3.      (name char(20),
  4.   capital char(20),
  5.   population num
  6.         )
  7.   ;
  8.   quit;
复制代码

  1. proc sql ; /*复制已有表格的表属性,创建一个空表*/
  2.     create table a1
  3.      like sashelp.class;
  4.   describe table a1;
  5.   quit;
复制代码

  1. proc sql outobs=10 ; /*从查询结果创建表*/
  2.     create table a as
  3. select * from sashelp.class(drop=sex);
  4. quit;
复制代码



插入行/列
  1. proc sql;
  2.    insert into countries        /*用set向表格总插入行*/
  3.        set
  4.             name="bangladesh",
  5.          capital="dhaka",
  6.    population=126391060
  7.     set
  8.             name="japan",
  9.             capital="tokyo",
  10.             population=126352003
  11.        ;
  12. quit;
复制代码

  1. proc sql;    /*用values向表格总插入行*/
  2.     insert into countries
  3.     values("pakistan","islamabad",123060000)
  4.     values("nigeria","lagos",99062000);
  5. quit;
复制代码

  1. proc sql;  /*用select筛选符合条件的行插入表格*/
  2.    create table newcountries
  3.        like countries;
  4.     insert into newcountries
  5.         select * from countries where population ge 120000000;
  6. quit;
复制代码

  1. proc sql;  /*插入列*/
  2.    alter table countries
  3.       add density num label="population density" format=6.2;
  4.    update countries
  5.      set density=population/10;
  6. quit;
复制代码


更新
  1. proc sql;  /*统一更新变量的所有值*/
  2.     update countries
  3.     set population=population*0;
  4. quit;
复制代码

  1. proc sql ;   /*有条件更新*/
  2.    update countries
  3.       set population = population*1.05 where name like "b%";
  4.    update countries
  5.       set population =population * 1.07 where name in("japan","russia");
  6. quit;
复制代码


删除
  1. proc sql ; /*删除行*/
  2.    delete from countries where population=0;
  3. quit;
复制代码

  1. proc sql ;  /*删除列*/
  2.    alter table countries
  3.       drop population;
  4.    quit;
复制代码

  1. proc sql; /*删除表*/
  2.    drop table countries;
  3. quit;
复制代码


综合应用
  1. proc sql ;
  2.    create table test like sashelp.class ;
  3.    insert into test select * from sashelp.class;
  4.    alter table test add new num format=dollar.;
  5.    update test set new = height* 1.2 where height<=60;
  6.    update test set new= height * case when height <= 60 then 1.2 else 1 end;
  7. quit;
复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

客服中心
关闭
在线时间:
周一~周五
8:30-17:30
QQ群:
653541906
联系电话:
010-85786021-8017
在线咨询
客服中心

意见反馈|网站地图|手机版|小黑屋|EPS数据狗论坛 ( 京ICP备09019565号-3 )   

Powered by BFIT! X3.4

© 2008-2028 BFIT Inc.

快速回复 返回顶部 返回列表