Advertisement
Guest User

Untitled

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