Solved

# SAS proc freq counting

Posted on 2009-12-16
915 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

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

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

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

## Featured Post

### Suggested Solutions

Read about achieving the basic levels of HRIS security in the workplace.
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of demâ€¦
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filledâ€¦

#### Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!