BookmarkSubscribeRSS Feed
t1000
Calcite | Level 5

Hello,

 

i am searching for a solution to determine and put out the largest and second value in a proc freq analysis. The proc freq look as the follow:

 

proc freq data = Personen (where = (
sex = '1' AND
type in ('X','Y','Z') ));
title 'Sex Types';
tables typ * geschlecht
/ NOROW NOCOL Nopercent format=commax18.0 out=WORK.sex_type;
run;

 

In Pesonen is a variable like 'tallness', with a numeric tallness value. Now i want to give out the tallest and the second tallest person in the defined group, each in an own column in the table above.

 

Do you haven idea?

 

T1000

 

 

 

4 REPLIES 4
Rick_SAS
SAS Super FREQ

See the article "Create a bar chart with only a few categories," which starts by using PROC FREQ to extract the top categories.

 

The main idea is to use the ORDER=FREQ option to sort the categories and use the OUT= option on the TABLES statement to save the categories to a data set. Here is an example of the top 2 categories of vehicles:

 

proc freq data=sashelp.cars ORDER=FREQ noprint;
  tables make / out=FreqOut;
run;

proc print data=FreqOut(obs=2);
run;
Rick_SAS
SAS Super FREQ

I just noticed that you have a 2-way table. Therefore you need to throw in a PROC SORT call to find the two cells that have the largest frequency counts:

 

proc sort data=FreqOut;
by Count;
run;

ballardw
Super User

It might help to show what your output is expected to look like.

Are you looking for the tallest within each level of Type (or typ) or combination of typ * geschlecht

or overall in the data set?

t1000
Calcite | Level 5

Thank´s a lot for your replies. As output I am looking for the second tallest observation in the combination of typ* geschlecht. Like the Maximum in proc means, but just the second Maximum (I have just one variable for analysis and one for classification) - I hope that´s the correct translation.

 

Is it possible to sort in a data step a select the second observation of a variable?

 

I wish you a nice Weekend

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 3179 views
  • 0 likes
  • 3 in conversation