BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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;
2 REPLIES 2
Cynthia_sas
SAS Super FREQ
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
data_null__
Jade | Level 19
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]

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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