BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
nayab_shaik
Calcite | Level 5

Hi Team,

 

How To Find out third height in sashelp.class by using data step and proc step

 

Advance Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
proc univariate data=sashelp.class nextrval=3;
var height;
run;

View solution in original post

5 REPLIES 5
Patrick
Opal | Level 21

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. 

PeterClemmensen
Tourmaline | Level 20

Using PROC RANK

 

proc rank data=sashelp.class out=want(where=(Rank=3)) descending ties=dense;
   var height;
   ranks Rank;
run;
Oligolas
Barite | Level 11
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 -

Patrick
Opal | Level 21

@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;
Ksharp
Super User
proc univariate data=sashelp.class nextrval=3;
var height;
run;

SAS Innovate 2025: Call for Content

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!

Submit your idea!

How to Concatenate Values

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.

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
  • 5 replies
  • 1065 views
  • 0 likes
  • 5 in conversation