Advertisement
Guest User

Untitled

a guest
Jan 19th, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SAS 2.08 KB | None | 0 0
  1. *SQL part 2;
  2. proc sql;
  3.     create table z1 as
  4.     select make, count(*) as cnt,
  5.         sum(invoice) as suma
  6.     from sashelp.cars
  7.     group by make;
  8.  
  9. proc sql;
  10.     create table z2 as
  11.     select make, count(*) as cnt,
  12.         sum(invoice) as suma
  13.     from sashelp.cars
  14.     where type="sedan"
  15.     group by make
  16.     having count(*) > 10;
  17.  
  18. proc sql;
  19.     create table z3 as
  20.     select make, count(*) as cnt,
  21.         count(distinct type) as cnt2,
  22.         sum(case when invoice > 40000
  23.             then 1 else 0 end) as col1,
  24.         sum(case when invoice <= 40000
  25.             then 1 else 0 end) as col2,
  26.         calculated cnt = calculated col1 +
  27.             calculated col2,
  28.         sum(type="Sedan") as sedan_cnt,
  29.         sum(type="SUV") as suv_cnt
  30.     from sashelp.cars
  31.     group by 1;
  32.  
  33. proc sql;
  34.     create table One(x num, a char(1));
  35.     insert into One
  36.         values(1, 'a')
  37.         values(4, 'b')
  38.         values(5, 'c');
  39.  
  40.     drop table One;
  41.    
  42.     create table One(x num, a char(1));
  43.     insert into One
  44.         values(1, 'a')
  45.         values(4, 'b')
  46.         values(5, 'c');
  47.  
  48.     create table two(x num, a char(1));
  49.     insert into two
  50.         values(2, 'x')
  51.         values(2, 'y')
  52.         values(3, 'z');
  53.  
  54.     create table z4 as
  55.     select t.*, b
  56.     from one as t, two;
  57.  
  58.     create table z5 as
  59.     select *
  60.     from one as t, two
  61.     where t.X = two.X;
  62.  
  63.     create table z6 as
  64.     select t.*
  65.     from one as t inner join two
  66.     on t.x = two.x;
  67.  
  68.     create table z7 as
  69.     select t.*
  70.     from one as t left join two
  71.     on t.x = two.x;
  72.  
  73.     create table z8 as
  74.     select coalesce(t.x, two.x) as x
  75.         ,t.x as x_one
  76.         ,a
  77.         ,two.x as x_two
  78.         ,b
  79.     from one as t full join two
  80.     on t.x = two.x;
  81. quit;;;;
  82.  
  83.  
  84. data pierwsza;
  85. do id=1 to 10 by 1;
  86. kolumna_a = 'A';
  87. kolumna_b = id*2;
  88. output;
  89. end;
  90. run;
  91.  
  92. data druga;
  93. do id=1 to 10 by 1;
  94. kolumna_a='A';
  95. kolumna_b=id*2;
  96. if id=1 then kolumna_b=1;
  97. if id=10 then kolumna_b=10;
  98. output;
  99. end;
  100. run;
  101.  
  102. proc sql;
  103.     create table z9 as
  104.     select * from pierwsza
  105.     union all
  106.     select * from druga;
  107.  
  108.     create table z10 as
  109.     select * from pierwsza
  110.     union
  111.     select * from druga;
  112.  
  113.     create table z11 as
  114.     select * from pierwsza
  115.     intersect
  116.     select * from druga;
  117.  
  118.     create table z12 as
  119.     select * from pierwsza
  120.     except
  121.     select * from druga;
  122. quit;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement