Hi Team,
How To Find out third height in sashelp.class by using data step and proc step
Advance Thanks
proc univariate data=sashelp.class nextrval=3;
var height;
run;
Welcome to the SAS community.
Use a Proc Sort and sort by height.
Then use a data step, set...; by height and select the 3rd observation (if _n_=3) - or alternatively use the obs and firstobs dataset options for the table used with the SET statement to directly select the 3rd option only.
Using PROC RANK
proc rank data=sashelp.class out=want(where=(Rank=3)) descending ties=dense;
var height;
ranks Rank;
run;
DATA _null_;
if 0 then set sashelp.class;
declare hash h(dataset:'sashelp.class',ordered: 'a');
h.definekey('height');
h.definedata(ALL:'YES');
h.definedone();
h.output(dataset:'want');
RUN;
*now see the data has already been sort by name age;
PROC PRINT data=want(firstobs=3 obs=3);RUN;
- Cheers -
@nayab_shaik wrote:
Hi Team,
How To Find out third height in sashelp.class by using data step and proc step
Given your question I assume you're a total beginner and that this is sort of an almost first exercise for you. If that's true then please ignore any of the more advanced coding suggestions.
In my opinion Proc Rank is the "best" approach as it also deals with ties. So that's likely one of the Proc's you're going to look into in one of your next lessons.
For now keep it simple and on your level. Below is "spoiler" code. It would be better to first try on your own as that's how you learn.
Going forward: People are more than happy to help here but I suggest always try first on your own and then eventually post your not yet working code and explain us where you're stuck. Doing it this way will give you often very helpful answers from which you can learn a lot. And the answers will be more likely on your skill level as looking into your code people can better understand where you're coming from.
proc sort data=sashelp.class out=work.class;
by height;
run;
data want_1;
set work.class;
by height;
if _n_=3;
run;
data want_2;
set work.class(firstobs=3 obs=3);
run;
proc univariate data=sashelp.class nextrval=3;
var height;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.