Hi,
I'm trying to drop variables and rename variables in a dataset.
I have var1 and var2 in the orignal dataset and am converting them into percentages using arrays. I'd like the variables in the output dataset to have the same names var1 and var2 so I'm trying to rename the new variables I created (pctvar1 pctvar2) to become var1 and var2 and also drop the old var1 and var2 variables that I don't need.
data round (drop=var1 var2)
rename= (pctvar1=var1 pctvar2=var2);
set first;
*create percentages;
array mult var1 var2;
array pct pctvar1 pctvar2;
do over mult
pct=mult*100;
end;
*--round to nearest tenth;
do over pct;
pct=round(pct, .1);
end;
run;
What am I doing wrong? thanks!
Ignore my stupid calculations, but it looks like you want to do the following, in which case it's just a matter of getting your parentheses correct:
data first;
var1 = 1;
var2 = 1;
run;
data round(drop = var1 var2 rename= (pctvar1=var1 pctvar2=var2));
set first;
pctVar1 = var1 / 10;
pctVar2 = var2 / 10;
run;
A little reformatting of your DATA statement will probably make the error more obvious.
data
round (drop=var1 var2)
rename= (pctvar1=var1 pctvar2=var2)
;
You have one output dataset name ROUND with the DROP= dataset option.
Then it looks like you are starting to also define another output dataset named RENAME, but you added an extra = sign after the data set name.
So fixing the nesting of your () so that you have just one output dataset you get this syntax:
data round
(drop=var1 var2
rename= (pctvar1=var1 pctvar2=var2)
)
;
It probably is easier to type if you just use the DROP and RENAME statements instead of adding dataset options to the output dataset.
data round ;
set .... ;
....
drop var1 var2;
rename pctvar1=var1 pctvar2=var2;
run;
Thank you both! Super helpful!!
data first;
var1 = 1;
var2 = 1;
var3= 3;
run;
data round (drop=var3 rename=(var1=pctvar1 var2=pctvar2));
set first ;
Var1 = var1 / 10;
Var2 = var2 / 10;
run;
you dont need drop the variable its been already renamed
Dataset options are processed in the alphabetical order:
Drop=/Keep= first
Rename= second
Where= last
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.