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 (September 2011, week 5)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 29 Sep 2011 22:11:42 -0400
Reply-To:     Tom Abernathy <tom.abernathy@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Tom Abernathy <tom.abernathy@GMAIL.COM>
Subject:      Re: How to repeat multiple statements in a datastep?

If you want to use array processing then you will need to query the variable names to find out the "team" names and how many there are. You can use this list to generate the list of variable names of the both the weekly values and for the generated ratio variables. In this example we are using PROC SQL to generate code fragments into macro variables.

data have; input ID abc1-abc4 cca1-cca4; cards; 1 5 5 4 4 3 3 2 2 2 3 3 4 4 5 6 3 4 ;

proc sql noprint ; select team||'_r' , team||'1-'||team||'4' into :rlist separated by ' ' , :vlist separated by ' ' from (select distinct substr(name,1,3) as team length=3 from dictionary.columns where libname='WORK' and memname='HAVE' and upcase(name) ne 'ID' ) ; %let nteams=&sqlobs; quit;

data want ; set have ; array val(&nteams,4) &vlist; array ratio(&nteams) &rlist; do team = 1 to 2 ; ratio(team) = sum(val(team,1),val(team,2))/sum(val(team,3),val(team,4)); end; run;

data _null_; set; put (id abc: cca:) (=) ; run;

ID=1 abc1=5 abc2=5 abc3=4 abc4=4 abc_r=1.25 cca1=3 cca2=3 cca3=2 cca4=2 cca_r=1.5 ID=2 abc1=3 abc2=3 abc3=4 abc4=4 abc_r=0.75 cca1=5 cca2=6 cca3=3 cca4=4 cca_r=1.5714285714


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