Help using Base SAS procedures

Need only 12 observations how do I limit it.

Not applicable
Posts: 0

Need only 12 observations how do I limit it.

Hi I need only 12 highest observations how and where do I put the statement to limit the number of observations.My code is below:


proc freq data = report.Fiscal08_datanodup order = freq;
tables DIA_1;
Posts: 9,367

Re: Need only 12 observations how do I limit it.

Posted in reply to deleted_user
PROC FREQ is, essentially, creating a summary report -- given your code. There are no "observations" coming out of PROC FREQ -- FREQ is producing a report that can have titles and footnotes -- but essentially, just a REPORT.

If you wanted to create an output dataset, using PROC FREQ, then you would need to investigate how the OUT= option works or how the ODS OUTPUT destination works to create an OUTPUT dataset.

PROC FREQ does support WHERE statement processing. So these would all be valid PROC FREQs:
proc freq data=sashelp.class;
where sex = 'F';
tables age;

proc freq;
where sales gt 10000;
tables product;

Also, I'm not sure I understand what you want. If you had this data (sorted in descending order) what would you envision:
id num
a1 1000
b2 999
c3 998
d4 997
e5 996
f6 995
g7 994
h8 993
i9 992
j10 991
k11 990
l12 989
m13 988
n14 987
a1 14
b2 13
c3 12
d4 11
e5 10
f6 9
g7 8
h8 7
i9 6
j10 5
k11 4
l12 3
m13 2
n14 1

Possible outputs:
1) only the first 12 with the highest values for num. In this scenario, you would pick off the first 12 observations from the detail data and either create a report or an output dataset;
2) add up all the values for num by id and THEN pick off the highest 12 -- for example, in this scenario, ID of A1 would have a value of 1014 for NUM (the sum of the 2 observations for ID=AI) -- this could be either a report or an output dataset
3) summarize all the values, find the IDs of the 12 highest and then go back and get ALL the observations for these highest IDs. In this scenario, you would have 2 observations for A1 on a report or in an output dataset: [pre]
id num
a1 1000
a1 14
. . .

Depending on the result you want, PROC FREQ may not be the path to follow.

Respected Advisor
Posts: 3,852

Re: Need only 12 observations how do I limit it.

Posted in reply to deleted_user
Like Cynthia said you will need to make your own report. But this could help get you started. The out= data from PROC FREQ is in the order you desire and you can use OBS=12 data set option to subset the data.

proc plan;
factors DIA_1=20 freq=1 of 200 /noprint;
output out=dia;
proc freq order=freq;
tables DIA_1 / out=top12;
weight freq;
proc print data=top12(obs=12);
Ask a Question
Discussion stats
  • 2 replies
  • 3 in conversation