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



how do i get last 10obs from a dataset when we don't know about the number of obsevations in ..

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

how do i get last 10obs from a dataset when we don't know about the number of obsevations in ..

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

how do i get last 10obs from a dataset when we don't know about the number of obsevations in ..

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

how do i get last 10obs from a dataset when we don't know about the number of obsevations in ..

Answer / naveen

Thank you Shiva

Is This Answer Correct ?    6 Yes 6 No

how do i get last 10obs from a dataset when we don't know about the number of obsevations in ..

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

how do i get last 10obs from a dataset when we don't know about the number of obsevations in ..

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

how do i get last 10obs from a dataset when we don't know about the number of obsevations in ..

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

Post New Answer

More SAS Interview Questions

6) Explain about below automatic variables a) _N_ b) _ERROR_ c) _CHAR_ d) _NUMERIC_ e) _ALL_ f) FIRST.BY VARIABLE g) LAST.BY VARIABLE h) _NAME_ i) _TYPE_ j) _FREQ_ k) _STAT_ l) _BREAK

1 Answers   IBM, SAS,


How the Excel file enter into the SAS environment without Code of Infile & Import procs,if i have no file Conversion?

3 Answers   Reddy Labs,


What are the five ways to do a table lookup in sas? : sas-grid-administration

0 Answers  


SAS System ?

5 Answers  


how will you location sas platform applications available from web browser? : Sas-bi

0 Answers  






In the flow of DATA step processing, what is the first action in a typical DATA Step?

6 Answers   Accenture,


What is the difference between informat and format statement?

1 Answers  


How will you use the WHO Drug Dictionary for Reporting Clinical Trials?

0 Answers  


what is the diff b/w verification validation in sas

3 Answers   SAS,


how do u identify a macro variable

5 Answers  


How to write duplicate records into a separate dataset using sort?

4 Answers   HSBC,


Can we use where and having clauses in a single SAS program. ex: proc sql;     select a,b,c from test      where state in 'KA'      and having <some condition>. Is the above program run correctly, if not why ?     

4 Answers   UHG,


Categories