I have a data set with 1000 observations. I want to only print out the last observation. Using the following:
proc print data=apple(firstobs = 1000 obs = 1000);
run;
I can get the last observation. But I have to know in advance that my data set has 1000 observations. How do I do this without knowing this?
There are many ways you could do this. Here are two:
proc sql noprint;
select n(var1) into :nobs
from apple;
quit;
proc print data=apple(firstobs=&nobs); run;
This just reads the number of observations into a macro variable, and then use that to specify the first observation. (Note that var1
refers to a variable in your data.)
Another approach would be to create a data view that only keeps the last observation and then print that:
data tmp / view=tmp;
set apple nobs=nobs;
if _n_=nobs;
run;
proc print data=tmp; run;
I think that the end
option for the SET
, MERGE
, MODIFY
, or UPDATE
statement is very useful.
data x;
do i = 1 to 1000;
output;
end;
run;
data x;
set x end = _end;
end = _end;
proc print data = x;
where end;
run;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With