how do i get last 10obs from a dataset when we don't know
about the number of obsevations in that dataset?
Answers were Sorted based on User's Feedback
Answer / raghu
proc sql;
select count(*) into : cnt from ds;
quit;
data ds1;
set ds(firstobs=%eval(&cnt-9) obs=&cnt);
run;
| Is This Answer Correct ? | 21 Yes | 0 No |
Answer / shiva
data a;
do i=1 to 100;
output;
end;
run;
data data1;
set a nobs=tot;
if _n_ gt( tot-10) then output data1;
run;
| Is This Answer Correct ? | 20 Yes | 4 No |
Answer / harshal r
data air;
set sashelp.air nobs=tot;
if _n_ gt( tot-10) then output;
run;
| Is This Answer Correct ? | 8 Yes | 1 No |
Answer / pratik
Suppose we have dataset like sasuser.admit.
we dontknow how many obs are there in this dataset.
then we can use
Proc contents data=sasuser.admit n;
run;
it will come the total no of obs in this dataset.
after doing this you will get 21 obs are there.
data dsn1;
set sasuser.admit(firstobs=12 obs=21);
run;
proc print data=dsn1;
run;
then you will get last 10 obs.
| Is This Answer Correct ? | 2 Yes | 2 No |
Answer / sumit
data new;
set old;
n = _N_;
run;
Proc sort data = new;
by descending n;
run;
Option OBS= 10;
Proc sort data = new (drop = n);
by descending n;
run;
| Is This Answer Correct ? | 2 Yes | 3 No |
Answer / its me
Shiva, ur answer is also correct . and here goes another
one dear..
data W;
set X;
if _n_ > 95 then output;
run;
As the total no. of obs are 100, the last five observations
will be be in ur output dataset..
Cheers!!!
| Is This Answer Correct ? | 1 Yes | 14 No |
How can a SAS WEB REPORT STUDIO USER identify which report tabs they have been permitted without entering the SAS WEB REPORT STUDIO
how do you test for missing values? : Sas programming
We have a string like this "kannafromsalembut" ,from this i want to get only "fromsal" (but one condition with out using substring function)here we can not use scan because in the given string there is no delimeter? so give ans without out using substring ?
i have a data set with 20 observations i want label from 8 to 15 observations ? how you create this one.
What is SAS? What are the functions does it performs?
name the scheduler for scheduling job and explain the scheduler? : Sas-di
what does .. meant in sas macros
What do you code to create a macro? : sas-macro
When looking for data contained in a character string of 150 bytes, which function is the best to locate that data: scan, index, or indexc?
how to debug and test the sas program? : Sas-administrator
explain the use of % includes a statement in sas? : Sas-administrator
What are the new features included in the new version of SAS Programming Language?