LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (October 2002, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 2 Oct 2002 13:54:38 -0700
Reply-To:     Dale McLerran <stringplayer_2@YAHOO.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Dale McLerran <stringplayer_2@YAHOO.COM>
Subject:      Re: Creating a variable with N/D and percent
Comments: To: Amanda <amrlar2002@yahoo.com>
In-Reply-To:  <200210021949.g92JnTh19486@listserv.cc.uga.edu>
Content-Type: text/plain; charset=us-ascii

Amanda,

I would approach this through the procedure FREQ which will generate the counts and percentages for you. Here is some sample code:

data test; input id A B C; cards; 1 0 0 1 2 1 1 0 3 1 1 0 4 1 1 1 5 1 1 1 6 1 1 1 7 1 1 1 8 1 0 0 9 0 1 1 10 1 1 1 11 1 1 1 12 1 1 0 13 1 1 1 14 1 1 0 15 0 0 1 16 1 1 1 ;

ods output OneWayFreqs=summary; proc freq data=test; tables a b c; run;

data final; set summary(keep=table frequency percent cumfrequency); by table notsorted; if last.table; rename frequency=numerator cumfrequency=denominator; run;

proc print data=final; run;

This does not create a single record with variables NUM_A DENOM_A PCT_A NUM_B DENOM_B PCT_B NUM_C DENOM_C PCT_C Rather, it creates a dataset with NUMERATOR DENOMINATOR PERCENT variables, and a variable which indicates which of A, B, or C variables the statistics represent. I find the latter structure more appealing, myself. If you want all statistics on one record, then you could code

proc means data=test; var a b c; output out=final n=denom_a denom_b denom_c sum=num_a num_b num_c mean=pct_a pct_b pct_c; run;

data final; set final; pct_a = 100*pct_a; pct_b = 100*pct_b; pct_c = 100*pct_c; run;

One or the other of these approaches should do the job for you. Whenever possible (unless your name is Paul Dorfman), let an existing procedure do the work for you.

Dale

--- Amanda <amrlar2002@YAHOO.COM> wrote: > I am fairly new to SAS and have a problem I just cant seem to figure > out. > I have the following dataset that for each variable I need to create > a > variable that contains: Numerator(number of observations = > 0)/Denominator > (number of observations = to 1 or 0) and percent of N/D. What's the > best > way to approch this? > id A B C > 1 0 0 1 > 2 1 1 0 > 3 1 1 0 > 4 1 1 1 > 5 1 1 1 > 6 1 1 1 > 7 1 1 1 > 8 1 0 0 > 9 0 1 1 > 10 1 1 1 > 11 1 1 1 > 12 1 1 0 > 13 1 1 1 > 14 1 1 0 > 15 0 0 1 > 16 1 1 1 > > Thanks

===== --------------------------------------- Dale McLerran Fred Hutchinson Cancer Research Center mailto: dmclerra@fhcrc.org Ph: (206) 667-2926 Fax: (206) 667-5977 ---------------------------------------

__________________________________________________ Do you Yahoo!? New DSL Internet Access from SBC & Yahoo! http://sbc.yahoo.com


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