[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
Solved

# SAS proc freq counting

Posted on 2009-12-16
Medium Priority
979 Views
What SAS code do I add to this statement to get back info only for instances where ID count > 1?   I've already sorted the file by ID.
``````proc freq data=combined_03;
by ID;
tables TYPE RESULT / NOPERCENT;
run;
``````
0
Question by:dhssra

LVL 18

Assisted Solution

Cory Vandenberg earned 248 total points
ID: 26081247

http://www2.sas.com/proceedings/sugi30/263-30.pdf

I believe you may be able to do what you want by creating an output dataset, then printing that dataset with a WHERE clause that only prints COUNT > 1.

Something like the code below.

WC
``````proc freq data=combined_03 noprint;
by ID;
tables TYPE RESULT / NOPERCENT out=freq_results;
run;

proc print data=freq_results;
where COUNT > 1;
run;
``````
0

Accepted Solution

tquakenbush earned 252 total points
ID: 26081669
I've attached some code that does some pre-processing of the data prior to the Proc Freq.

1) creates a temporary table with the count of IDs
2) delete those with count = 1
3) create a temporary table from combined_03 with only those IDs with count > 1
4) Proc Freq the table from step 3)
``````* create temp table with count by ID;
proc freq data=combined_03 order= freq;
tables ID / nopercent noprint out= ID_count;
run;

* delete those IDs with count= 1;
data ID_count (keep= ID);
set ID_count;
if count = 1 then delete; run;

* create temp table with records for those IDs with count more than one;
data merge_for_freq;
merge combined_03 (in= a) ID_count (in= b);
by ID;
if a and b;
run;

proc freq data=merge_for_freq;
by ID;
tables TYPE RESULT / NOPERCENT;
run;
``````
0

Author Closing Comment

ID: 31667063
Solutions work, and process in about the same length of time.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.