Advertisement
Guest User

Untitled

a guest
Jan 18th, 2020
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SAS 1.98 KB | None | 0 0
  1. proc sql;
  2. create z1 as select make,count (*) as cnt,count(distinct type) as type_cnt,sum(invoice)as suma  from sashelp.cars() group by make;
  3. create table z2 as select make,count(*) as cnt,count(distinct type) as type_cnt,sum(invoice) as suma from sashelp.cars where origin='Europe' group by make having count(*)>5;
  4. create table z3 as select make,count(*) as cnt, sum(case when invoice >= 40000 then 1 else 0 end) as col1, sum(case when invoice < 40000 then 1 else 0) as col2,
  5. calculated cnt = calculated col1 + calculated col2 as col3,
  6. sum(type='Sedan') as sedan_cnt,
  7. sum(type='Suv') as suv_cnt,
  8. sum(type'Sports') as sports_cnt,
  9. from sashelp.cars
  10. group by 1;
  11. create table z4 as  select make,count(*) as cnt,(count(*)/ (select count(*) fromsashelp.cars))*100 A C21
  12. FROM sashelp.cars
  13. group by make;
  14.  
  15. create table ONE
  16. values (1,'a')
  17. values(2,'b')
  18. values(2,'c')l
  19. create table two(X num, Bchar1(1));
  20. insert into two
  21. values (1,'x')
  22. values(1,'y')
  23. values(3,'z');
  24. create table z5 as select t.*, two.B from one as t,two
  25. *"inner join";
  26. create table z6 as select t.6*,two.B from one as t,two where t.X=two.B from one as t inner join two on t.X=two.X;
  27. *left/right join;
  28. create table z8 as select t.*,two.B
  29. from one as t left join two on t.x=two.X;
  30. *full join;
  31. create table z8 as select coalesce(t.X,two.X) as X, t.X as one_x, two.X as two x, a,b from  one as t full join two t.x=two.x;
  32. data pierwsza;
  33. do i=1 to 10 by 1;
  34. kolumna_a='A';
  35. kolumna_b=i*2;
  36. output;
  37. end;
  38. run;
  39.  
  40. data druga;
  41. do i=1 to 10 by 1;
  42. kolumna_a='A';
  43. kolumna_b=i*2;
  44. if i=1 then kolumna_b=1;
  45. if i=10 then kolumna_b=10;
  46. output;
  47. end;
  48. run;
  49. *operatory;
  50. proc sql;
  51. create table z1 as select * from pierwsza union all /*suma wierszy, nie usuwa duplikatów*/
  52. select * from druga
  53. proc sql;
  54. create table z12 as select * from pierwsza intersect  /*część pierwsza*/
  55. select * from druga
  56.  
  57. proc sql;
  58. create table z122 as select * from pierwsza  except select * from druga /*suma wierszy, nie usuwa duplikatów*/
  59. select * from druga
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement