03-22-2017 07:41 PM
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);
array mult var1 var2;
array pct pctvar1 pctvar2;
do over mult
*--round to nearest tenth;
do over pct;
What am I doing wrong? thanks!
03-22-2017 07:50 PM
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;
03-22-2017 09:14 PM
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;