LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (January 1997, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Fri, 17 Jan 1997 15:24:00 -0500
Reply-To:   Dave_Mabey_at_RDA8POSTOFFICE1%RDCCMAIL%READERSDIGEST@RMAIL.COM
Sender:   "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:   Dave_Mabey_at_RDA8POSTOFFICE1%RDCCMAIL%READERSDIGEST@RMAIL.COM
Subject:   Re[3]: comm1-comm6 problem
Content-type:   text/plain; charset=US-ASCII

New Text Item: Re[2]: comm1-comm6 problem

It must be Friday afternoon. No sooner did I post the following reply than it occurred to me that I probably misunderstood what Lisa meant when she stated:

">I have a total of about 67 codes (numeric), any of which can be found >among six consecutive fields (comm1 comm6), although for each >observation, a code can only show up once."

At first I took this to mean that all but one of the the variables comm1-comm6 would have missing values, leaving only one of the variables containing a code. (see my first reply)

A more reasonable interpretation is that a code will not repeat itself in a observation, but comm1-comm6 will all have different codes. If that is the case, then this code should produce the desired report. (if you want an output dataset named "COMMOUT". then put "create table commout as" before the select statement):.

proc sql; select key, count(*) from ( select comm1 as key from comfile union all (select comm2 as key from comfile) union all (select comm3 as key from comfile) union all (select comm4 as key from comfile) union all (select comm5 as key from comfile) union all (select comm6 as key from comfile)) group by key;

The union statement can be a bit tricky. Be careful when you use it!

______________________________ Reply Separator ____________________________ _____ Subject: Re[2]: comm1-comm6 problem Author: Dave_Mabey_at_RDA8POSTOFFICE1%RDCCMAIL%READERSDIGEST@RMAIL.COM@INTERNET at RDNOTES Date: 1/17/97 1:36 PM

(Embedded image moved to file: PIC001.PCX) New Text Item: Re: comm1-comm6 problem

Lisa,

I would use the following.

PROC SQL; select case when comm1 ne . then comm1 when comm2 ne . then comm2 when comm3 ne . then comm3 when comm4 ne . then comm4 when comm5 ne . then comm5 when comm6 ne . then comm6 when comm7 ne . then comm7 else -1 end as index, count(*) from comfile group by index;

** Generic Signature **

______________________________ Reply Separator ____________________________ _____ Subject: Re: comm1-comm6 problem Author: j_weedon@ESCAPE.COM@INTERNET at RDNOTES Date: 1/16/97 11:11 AM

(Embedded image moved to file: PIC001.PCX) On Thu, 16 Jan 1997 08:51:23 -0500, Lisa Bastian <eagle89@EROLS.COM> wrote:

>I have a total of about 67 codes (numeric), any of which can be found >among six consecutive fields (comm1 comm6), although for each >observation, a code can only show up once. Is there any "easy" way to >count the occurrence of each individual code? ie., without an array and >a bunch of "if" statements? Thanx.

Please put a subject line in your posts. Does this do what you want:

%macro comms; data new (keep=comm); set old (keep=comm1-comm6); %do i=1 %to 6; comm=comm&i; output; %end; proc freq data=new; run; %mend; %comms

I'm not sure what your aversion to arrays is, but a non-macro solution with an array would be:

data new (keep=comm); set old (keep=comm1-comm6); array comms comm1-comm6; do over comms; comm=comms; output; end; proc freq data=new; run;

Jay Weedon. SMTPOriginator: owner-sas-l@VM.MARIST.EDU SMTPOriginator: owner-sas-l@VM.MARIST.EDU


Back to: Top of message | Previous page | Main SAS-L page