BookmarkSubscribeRSS Feed
newhand
Calcite | Level 5
suppose I have two data set:

data_set_1:

obs Var_1 Var_2 Var_3
1 002 003 001
2 1.02 0.09 0.23
3 0.02 0.56 1.08


data_set_2:

obs ID Name
1 001 Math
2 002 Phys
3 003 Chem

Now I want to create Data_Set_3 using following criteria:
Compare the first obs of data_set_1 with ID variables of data_set_2. If the result is same, the variable name of data_set_1 will change to the name of Name variables in data_set_2.

I hope I explained my question clearly. And the expected data_set_3 will be like:

data_set_3:

obs Phys Chem Math
1 002 003 001
2 1.02 0.09 0.23
3 0.02 0.56 1.08


Is there a easy way to do this? Thanks.
3 REPLIES 3
Ksharp
Super User
Yes.
There is an easy way to do this .
But this way is not suitable for the dataset with large obs.
[pre]
data data1;
input obs (var1 var2 var3) ($);
datalines;
1 002 003 001
2 1.02 0.09 0.23
3 0.02 0.56 1.08
run;

data data2;
input obs id $ name $;
datalines;
1 001 Math
2 002 Phys
3 003 Chem
;
run;
proc transpose data=data1(drop=obs) out=temp;
var var1 var2 var3;
run;
proc sort data=temp;
by col1;
run;
proc sort data=data2(drop=obs);
by id;
run;
data result;
merge temp(rename=(col1=id)) data2;
by id;
drop _name_;
run;
proc transpose data=result out=op(drop=_name_);
id name;
var id col2 col3;
run;
proc print ; run;
[/pre]


Ksharp
newhand
Calcite | Level 5
thank you, Ksharp.

Is it because "Transpose" will take too much time that this method is not suitable for dataset with too many obs?
Ksharp
Super User
No.
For the previous SAS release,the number of variables is limited for proc transpose.I am not sure the Current SAS is whether supported unlimited variables.

Ksharp Message was edited by: Ksharp

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 1170 views
  • 0 likes
  • 2 in conversation