|
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 -
|