登录
首页精彩阅读sas:利用SQL连接表
sas:利用SQL连接表
2016-08-07
收藏

sas:利用SQL连接表

基本语句:

select variable1, variable2, variable3.....from table

where condition1 and/or condition2....

group by variable1, variable2, variable3......

having condition1, condition2.....

order by variable1, variable2

select很简单

where一般就是对应from语句

group by一般都具有特殊目的,聚集函数连用

想要对group by之后的分组进行条件筛选,应该用having语句

order by 就是对结果进行排序,desc就是降序,默认是升序,和proc sort 的by 语句对比:只对一个变量有用,但是这里是加在变量后面, 而proc sort 是加在变量前面;

实例:

select sum(height) as sum label='总身高' format=4.1 from class

group by class

having calculated sum gt 150

order by sex desc;


join语句

(left/right/full)out join /inner join

a,b 笛卡尔积,常与where连用(连用后就算内连接)

外连接:左连接就是左表变量不变,右同,全的话就是有就连没就缺失值


table相关语句

create->insert->update->delete->alter

create 就是建立table

insert就是在table中添加行

update是在table中修改行

delete是在table中删除行

alter是修改列

create table as select variable from table1

是从table1中挑选变量到一个新的创建的table中

insert into table

set ...

这是往table中添加变量

insert into table

values (...)

这两种用法的结果基本是一样的

大家可以自己试一试

update table

set variable1=variable1*1.7

把表中的变量1放大1.7倍

delete from table where ...

将符合条件的行删除


alter相关语句

add是添加列

alter table

add col num format=4.1 label='...'

建立了一个数字型的新列

modify 是改变列的格式

alter table

modify col format=comma15.1

修改了col列的格式

drop 删除列

alter table

drop col1

删除掉了col1列

SQL

数据分析咨询请扫描二维码

客服在线
立即咨询