Help using Base SAS procedures

Need only 12 observations how do I limit it.

Reply
N/A
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:

Thanks.




proc freq data = report.Fiscal08_datanodup order = freq;
tables DIA_1;
run;
SAS Super FREQ
Posts: 8,740

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

Hi:
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:
[pre]
proc freq data=sashelp.class;
where sex = 'F';
tables age;
run;

proc freq data=sashelp.shoes;
where sales gt 10000;
tables product;
run;
[/pre]

Also, I'm not sure I understand what you want. If you had this data (sorted in descending order) what would you envision:
[pre]
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
[/pre]

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
. . .
[/pre]

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

cynthia
Respected Advisor
Posts: 3,777

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

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.

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