Guest User

Untitled

a guest
Aug 17th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. How do you print the last observation of a SAS data set?
  2. proc print data=apple(firstobs = 1000 obs = 1000);
  3. run;
  4.  
  5. proc sql noprint;
  6. select n(var1) into :nobs
  7. from apple;
  8. quit;
  9.  
  10. proc print data=apple(firstobs=&nobs); run;
  11.  
  12. data tmp / view=tmp;
  13. set apple nobs=nobs;
  14. if _n_=nobs;
  15. run;
  16.  
  17. proc print data=tmp; run;
  18.  
  19. %macro nobs (dsn);
  20. %let nobs=0;
  21. %let dsid = %sysfunc(open(&dsn));
  22. %if &dsid %then %let nobs = %sysfunc(attrn(&dsid,nobs));
  23. %let rc = %sysfunc(close(&dsid));
  24. &nobs
  25. %mend nobs;
  26.  
  27. %let n = %nobs(apple);
  28.  
  29. proc print data=apple (firstobs=&n obs=&n); run;
  30.  
  31. data x;
  32. do i = 1 to 1000;
  33. output;
  34. end;
  35. run;
  36.  
  37. data x;
  38. set x end = _end;
  39. end = _end;
  40. proc print data = x;
  41. where end;
  42. run;
Add Comment
Please, Sign In to add comment