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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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