Hi Everyone!
How can i rename "A" in var1 into A1, A2 and A3 based on 1, 8, and 25 in var2?
i.e lets have:
var1 var2
A 1
A 8
A 25
B 3
c 5
A 1
A 8
A 25
into
var1 var2
A1 1
A 2 8
A 3 25
B 3
c 5
A1 1
A 2 8
A 3 25
Thank you alot!
Not "renaming" that means something else in SAS regardless of how you use your variable var1.
One of the basic approaches to changing the value of a variable based on the value of a different variable is the IF /Then statement in a data step:
data want;
set have;
If var1='A' and var2=1 then var1='A1';
run;
Some potential gotchas exist with this though. The variable var1 will have a length associated with the variable. If the length is 1 (one) then attempting to add more characters at the end will fail as there is no room for the additional variable.
You can group similar values into a "DO block to avoid repeating some tests such as var1='A': The following code demonstrates that plus how to change the length of var1 if needed.
data want; length var1 $ 5; set have; If var1='A' then do; if var2=1 then var1='A1'; if var2=8 then var1='A2'; if var2=25 then var1='A3'; end; run;
Not "renaming" that means something else in SAS regardless of how you use your variable var1.
One of the basic approaches to changing the value of a variable based on the value of a different variable is the IF /Then statement in a data step:
data want;
set have;
If var1='A' and var2=1 then var1='A1';
run;
Some potential gotchas exist with this though. The variable var1 will have a length associated with the variable. If the length is 1 (one) then attempting to add more characters at the end will fail as there is no room for the additional variable.
You can group similar values into a "DO block to avoid repeating some tests such as var1='A': The following code demonstrates that plus how to change the length of var1 if needed.
data want; length var1 $ 5; set have; If var1='A' then do; if var2=1 then var1='A1'; if var2=8 then var1='A2'; if var2=25 then var1='A3'; end; run;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Lock in the best rate now before the price increases on April 1.
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.