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 21:53:39 -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?

You can use transpose to do it with having the use macro language or other code generation techniques.

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 transpose data=have out=v ; by id; run;

data v; set v; team = substr(_name_,1,3); week = input(substr(_name_,4),best.); run;

proc transpose data=v out=h prefix=week ; by id team ; id week ; var col1; run;

data h ; set h ; _name_=trim(team)||'_r' ; ratio = sum(week1,week2)/sum(week3,week4) ; run;

proc transpose data=h out=ratio (drop=_:) ; by id ; id _name_ ; var ratio ; run;

data want ; merge have ratio ; by id; 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