BookmarkSubscribeRSS Feed
Oleg_L
Obsidian | Level 7
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
2 REPLIES 2
abdullala
Calcite | Level 5
proc transpose data=a out=b;
id type;
var var1 - var9;
run;
Oleg_L
Obsidian | Level 7
Thank you very much for your help!
Oleg.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 811 views
  • 0 likes
  • 2 in conversation