knowledge-database (beta)

Current group: comp.soft-sys.sas

help on data reconstructure

help on data reconstructure  
Wrong Wang
 Re: help on data reconstructure  
Dennis Diskin
From:Wrong Wang
Subject:help on data reconstructure
Date:21 Jan 05 21:42:18 GMT
I am working on some data but I have some problem on reconstrct it.

In my data, each obs has may have at most 12 occupations (occupation1-
occupation12 ,character) and correspondent jobduration( jobduration1-12).
Occupation1 - occupation12 may have the same values. I don't want to keep
duplicate occupation values. I will unique occupation value and cummlative
jobduration. I will use the following example to make it clear:

obs=10433
occupation1=234
occupation2=354
occupation3= 34
occupation4=354
occupation5- occupation12=.

jobduration1=3
jobduration2=5
jobduration3= 6
jobduration4=7
jobduration5- jobduration12=.



occupation2 and occupation4 have the same value. I only want to keep one
of them, but the jobduration for this occpation=354 should be jobduration2+
jobduration4=5+7=12

How can I get the new dataset in sas?

Thanks
From:Dennis Diskin
Subject:Re: help on data reconstructure
Date:21 Jan 05 22:23:14 GMT
Wrong,

This may be more than you wanted to do but the following should give you data you can work with more easily. The same could also be done purely in datastep code using arrays.
If you want, you can convert the S dataset back to a horizontal structure.

Naturally, there would be ID's for by variables to be added to the code.

HTH,
Dennis Diskin

data a;
length occupation1-occupation12 jobduration1-jobduration12 8;
occupation1=234 ;
occupation2=354 ;
occupation3= 34 ;
occupation4=354 ;
jobduration1=3 ;
jobduration2=5 ;
jobduration3= 6 ;
jobduration4=7 ;
run;
proc transpose data=a out=b;
var occupation:;
var jobduration:;
run;
data m;
merge b(where=(upcase(substr(_name_,1,10)) eq 'OCCUPATION') rename=col1=occupation)
b(where=(upcase(substr(_name_,1,10)) eq 'JOBDURATIO') rename=col1=jobduration)
;
/* NOTE: no by statement */
drop _name_;
run;
proc summary data=m nway;
class occupation;
var jobduration;
output out=s(drop=_:) sum=jobduration;
run;


Wrong Wang wrote:
I am working on some data but I have some problem on reconstrct it.

In my data, each obs has may have at most 12 occupations (occupation1-
occupation12 ,character) and correspondent jobduration( jobduration1-12).
Occupation1 - occupation12 may have the same values. I don't want to keep
duplicate occupation values. I will unique occupation value and cummlative
jobduration. I will use the following example to make it clear:

obs=10433
occupation1=234
occupation2=354
occupation3= 34
occupation4=354
occupation5- occupation12=.

jobduration1=3
jobduration2=5
jobduration3= 6
jobduration4=7
jobduration5- jobduration12=.



occupation2 and occupation4 have the same value. I only want to keep one
of them, but the jobduration for this occpation=354 should be jobduration2+
jobduration4=5+7=12

How can I get the new dataset in sas?

Thanks
   

Copyright © 2006 knowledge-database   -   All rights reserved