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 2008, week 5)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Thu, 31 Jan 2008 03:37:41 -0500
Reply-To:   Gerhard Hellriegel <gerhard.hellriegel@T-ONLINE.DE>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Gerhard Hellriegel <gerhard.hellriegel@T-ONLINE.DE>
Subject:   Re: Simple Question

after correcting all your syntax errors, it does something. Don't know if it is what you need, but try it:

/* read input dataset */ data xin; input Job_Code $2. Female 2. Male 2. Total 2. pct 2.; cards; AS 10 10 20 20 CO 40 40 80 80 ; run; /* sort by job_code */; proc sort; by job_code; run; /* create transformed dataset */; data xout; set xin; by job_code; format gender $6. jobcode $2. gtotal 10. gpct percent.; retain jobcode ftotal mtotal jobtotal;

/* It doesn't work after this line. */

if first.job_code=1 then do; jobcode=' '; ftotal=0; mtotal=0; jobtotal=0; end; ftotal=female; mtotal=male; jobtotal=ftotal+mtotal; if last.job_code=1 then do; do i=1 to 2; if i=1 then do; gender='Female'; jobcode=job_code; gtotal=ftotal; gpct=gtotal/jobtotal; output; end; if i=2 then do; gender='Male'; jobcode=job_code; gtotal=mtotal; gpct=gtotal/jobtotal; output; end; end; end; keep gender jobcode gtotal gpct; run;

Gerhard

On Wed, 30 Jan 2008 12:07:52 -0800, Ayan <Ayan.H.Egeh@GMAIL.COM> wrote:

>Hi, > >Thanks for the code. But it doesn't work after some codes. > > >> >> A highly inelegant approach is shown below. It does the trick. >> Others will have prettier, more efficient code and some may know how >> to do what you want with PROC TRANSPOSE or something of that nature. >> >> */ read input dataset /*; >> data xin; >> input Job_Code $2. Female 2. Male 2. Total 2. pct 2.; >> cards; >> AS10102020 >> CO40408080 >> run; >> */ sort by job_code /*; >> proc sort; >> by job_code; >> run; >> */ create transformed dataset /*; >> data xout; >> set xin; >> by job_code; >> format gender $6. jobcode $2. gtotal 10. gpct percent.; >> retain jobcode ftotal mtotal jobtotal; > > >It doesn't work after this line. > > >> if first.job_code=1 then do; >> jobcode=' '; ftotal=0; mtotal=0; jobtotal=0; >> end; >> ftotal=female; >> mtotal=male; >> jobtotal=ftotal+mtotal; >> if last.job_code=1 then do; >> do i=1 to 2; >> if i=1 then do; >> gender='Female'; >> jobcode=job_code; >> gtotal=ftotal; >> gpct=gtotal/jobtotal; >> output; >> end; >> if i=2 then do; >> gender='Male'; >> jobcode=job_code; >> gtotal=mtotal; >> gpct=gtotal/jobtotal; >> output; >> end; >> end; >> end; >> keep gender jobcode gtotal gpct; >> run;- Hide quoted text - >> >> - Show quoted text -


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