Hello,
i have a dataset named "dep_ret1" with data shown below.
Variables var1-var9 are character.
nn type var1 var2 var3 var9
1 date1 1.01 1.02 1.03 1.09
3 total1 5906990 6115348 6217667 6670658
6 demand_r1 838138 723350 751973 822665
15 demand_c1 163593 201341 193274 175933
And i want to get the following structure from this data (dataset "dep_ret3" in the code below):
_NAME_ date1 total1 demand_r1 demand_c1
var1 1.01 5906990 838138 163593
var2 1.02 6115348 723350 201341
var3 1.03 6217667 751973 193274
var9 1.09 6670658 822665 175933
I'm getting this by the code below. But i don't like it. I think it's very "rough".
Is there another way to do this?
My code:
proc sort data=dep_ret1; by nn type; run;
proc transpose data=dep_ret1 out=dep_ret2; by nn type; var var1-var3 var9; run;
proc sort data=dep_ret2; by _name_; run;
data dep_ret3;
merge
dep_ret2 (where=(nn=1) keep=_name_ col1 nn rename=col1=date1)
dep_ret2 (where=(nn=3) keep=_name_ col1 nn rename=col1=total1)
dep_ret2 (where=(nn=6) keep=_name_ col1 nn rename=col1=demand_r1)
dep_ret2 (where=(nn=15) keep=_name_ col1 nn rename=col1=demand_c1);
by _name_ ;
drop nn;
run;
Message was edited by: Oleg_1976
Message was edited by: Oleg_1976