SAS proc freq counting

Posted on 2009-12-16
Last Modified: 2013-11-16
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;



Open in new window

Question by:dhssra
    LVL 18

    Assisted Solution

    Check out the following link.

    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.

    proc freq data=combined_03 noprint; 
            by ID; 
            tables TYPE RESULT / NOPERCENT out=freq_results; 
    proc print data=freq_results;
      where COUNT > 1;

    Open in new window


    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; 
    * 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;
    proc freq data=merge_for_freq; 
            by ID; 
            tables TYPE RESULT / NOPERCENT; 

    Open in new window


    Author Closing Comment

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
    Read about achieving the basic levels of HRIS security in the workplace.
    Video by: Steve
    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…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now