Help using Base SAS procedures

change variable name

Reply
New Contributor
Posts: 4

change variable name

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.
Super User
Posts: 10,023

Re: change variable name

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
New Contributor
Posts: 4

Re: change variable name

thank you, Ksharp.

Is it because "Transpose" will take too much time that this method is not suitable for dataset with too many obs?
Super User
Posts: 10,023

Re: change variable name

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
Ask a Question
Discussion stats
  • 3 replies
  • 118 views
  • 0 likes
  • 2 in conversation