在sql中增加case可以增加数据处理的灵活性,注意结尾的end
1 proc sql outobs=10; 2 title 'this is an example of sql and case'; 3 select wangnei,date, 4 case 5 when 200901<=date<=200903 then 'first' 6 when 200904<=date<=200906 then 'second' 7 else 'else' 8 end as season 9 from mysas.mmsone10 where date<=200912;11 quit;
---------sas 9.3 sql procedure user's guide page 35 or (49/418)
在where字句后还可以加上许多operator
any all between-and contains exists in isnull is missing like =*
in
1 proc contents data=mysas.ifthen; 2 run; 3 proc print data=mysas.ifthen (firstobs=1 obs=10); 4 run; 5 proc sql outobs=10; 6 title 'this is a instance of in'; 7 select * from mysas.ifthen 8 where date in(200901,200902) 9 order by shen descending;10 quit;
between and
1 proc sql outobs=10;2 title 'this is a try of between and';3 select * from mysas.ifthen4 where date between 200905 and 2010015 order by shen dscending;6 quit;
like
1 proc sql outobs=50;2 select * from &dataset3 where subporduct_code like 'z%' or subporduct_code like 'XX____';4 quit;
在where筛选条件中对于排序文本也可以用大于小于的逻辑来判断:eqt gtt ltt get let net.