Advertisement
Guest User

Untitled

a guest
Jan 18th, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SAS 1.48 KB | None | 0 0
  1. data z1;
  2. put _ALL_;
  3.     set sashelp.class;
  4.     put _ALL_;
  5.     weight2 = weight / 2;
  6.     put _ALL_;
  7. run;
  8.  
  9. *zliczenia;
  10. *chcemy obliczyć wartość samochodów w help.cars;
  11. data z2;
  12.     set sashelp.cars end=koniec;
  13.    
  14.     retain total 0; /* zapamiętaj zmienna wartość_po */
  15.     total = total + invoice;
  16.  
  17.     /* total + invoice */
  18.     if koniec then output;
  19. run;
  20.  
  21. *przetwarzanie w grupach;
  22. proc sort data = sashelp.cars out=cars;
  23.     by make; /* zmienna grupująca */
  24. run;
  25.  
  26.  
  27. data z3;
  28.     set cars;
  29.     by make; /* przetwarzanie w grupach */
  30.     col1 = first.make;
  31.     col2 = last.make;
  32. run;
  33.  
  34.  
  35. data z3;
  36.     set cars;
  37.     by make; /* przetwarzanie w grupach */
  38.     /*col1 = first.make;
  39.     col2 = last.make; */
  40.  
  41.     if first.make then do;
  42.         licznik = 0;
  43.         suma = 0;  
  44.     end;
  45.  
  46.     licznik + 1;
  47.     suma + invoice;
  48.  
  49.     if last.make then output;
  50.     keep make licznik suma;
  51. run;
  52.  
  53.  
  54. *sashelp.air;
  55.  
  56. data z4;
  57.     set sashelp.air;
  58.     rok = year(date);
  59. run;
  60.  
  61.  
  62. Proc sort data = z4 out = z4;
  63.     by rok;
  64. run;
  65.  
  66. data z5;
  67.     set z4;
  68.     by rok;
  69.  
  70.     if first.rok then suma = 0;
  71.  
  72.     suma + air;
  73.  
  74.     if last.rok then output;
  75.     keep rok suma;
  76. run;
  77.  
  78. *podaj 3 najdroższe auta dla każdej marki;
  79. proc sort data=sashelp.cars out=cars;
  80.     by make descending invoice;
  81. run;
  82.  
  83. data z6;
  84.     set cars;
  85.     by make;
  86.     if first.make then licznik = 0;
  87.  
  88.     licznik + 1;
  89.  
  90.     if licznik <= 3 then output;
  91. run;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement