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-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 3759 views
  • 0 likes
  • 3 in conversation