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

what is a method for assigning first.var and last.var to the by groupvariable on unsorted data? : Sas programming

0 Answers  


What statement do you code to tell SAS that it is to write to an external file? What statement do you code to write the record to the file?

2 Answers   Accenture,


What are the differences between proc means and proc summary?

0 Answers  


what is the difference between SET and MERGE?

19 Answers   CitiGroup,


how to read character value without using substr function in sas ?

3 Answers  






Name and describe three SAS functions that you have used, if any?

2 Answers  


How substr function works in sas?

0 Answers  


What is difference between rename and lable in sas?

10 Answers   Satyam,


how would you create a data set with 1 observation and 30 variables from a data set with 30 observations and 1 variable? : Sas programming

0 Answers  


What is the difference between Regression and Logistic Regression? Can u explain the Assumptions/Conditions?

3 Answers  


What is the order of evaluation of the comparison operators: + - * /** ()?

3 Answers   Quintiles,


what techniques and/or procs do you use for tables? : Sas programming

0 Answers  


Categories