07-13-2016 08:52 AM
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;
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?
07-13-2016 09:48 AM
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;
07-13-2016 01:14 PM
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;
07-13-2016 12:03 PM
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?
07-15-2016 09:00 AM
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