BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I have a Data set but i dont know the no of observations are there now i want the last 5 th observation.
2 REPLIES 2
GertNissen
Barite | Level 11
Here is one way of doing it.

[pre]
data input(keep=CharColumn);
input CharColumn $;
datalines;
H090301
C090302
I090303
H090304
C090305
I090306
H090307
C090308
I090309
;
run;

proc sql NOPRINT;
select nobs into :nobs
from sashelp.vtable
where libname='WORK' and memname ='INPUT';
quit;
%put &nobs;

data last5;
set input END=last;
if _n_ > (&nobs - 5) then output;
run;[/pre]
data_null__
Jade | Level 19
How about a more direct(access) approach?

[pre]
data input;
input CharColumn $;
obs + 1;
datalines;
H090301
C090302
I090303
H090304
C090305
I090306
H090307
C090308
I090309
;;;;
run;
data last5;
do point=nobs-4 to nobs;
set input point=point nobs=nobs;
output;
end;
stop;
run;
proc print;
run;

*** OR just compute FIRSTOBS and start reading from there.
proc sql NOPRINT;
select nobs-4 into :firstobs separated ' '
from sashelp.vtable
where libname='WORK' and memname ='INPUT';
quit;
%put FIRSTOBS=&firstobs;

proc print data=input(firstobs=&firstobs);
run;
[/pre]

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 619 views
  • 0 likes
  • 3 in conversation