@liebera wrote:
Hello, I am trying to create multiple new variables, but when I create a variable using conditional statements it overwrites the variable that I previously created.
Example:
data a;
set Pathway.Tang_pathwayfinal;
if ER=1 and HER2_best=2 then subtype=1;/*luminal A*/
else if ER=1 and HER2_best=1 then subtype=2;/*luminal B*/
else if ER=2 and PR=2 and HER2_best=2 then subtype=3;/*Triple Negative*/
else if ER=2 and PR=2 and HER2_best=1 then subtype=4;/*Her2 Overexpression*/
else subtype=.;
run;
data a;
set Pathway.Tang_pathwayfinal;
if ER=1 then ERnew=1;
else if ER=2 then ERnew=2;
else ERnew=.;
run;
In this example the ERnew variable will overwrite the subtype variable in my dataset and I am not sure why. It seems that I am restricted to creating only one variable. I am using SAS v. 9.4.
Please help, Thank you!
Put all the code into one data step.
data a;
set Pathway.Tang_pathwayfinal;
if ER=1 and HER2_best=2 then subtype=1;/*luminal A*/
else if ER=1 and HER2_best=1 then subtype=2;/*luminal B*/
else if ER=2 and PR=2 and HER2_best=2 then subtype=3;/*Triple Negative*/
else if ER=2 and PR=2 and HER2_best=1 then subtype=4;/*Her2 Overexpression*/
else subtype=.;
if ER=1 then ERnew=1;
else if ER=2 then ERnew=2;
else ERnew=.;
run;
... View more