Hello,
I have a dataset with ~200 variables. I need to rename the entire dataset with the exception of 10 variables. Previous analysts typed out each of the 190 variables, but I'm trying to streamline the code. The following is what I came up with, and works perfectly....except it renames all the variables. Can someone help me figure out how to remove just the 10 that shouldn't be renamed?
Thank you.
DATA dnld15;
set dnld.2015;
run;
proc sql noprint;
select cats(name,'=',name,'Z')
into :suffixlist
separated by ' '
from dictionary.columns
where libname = 'WORK' and memname = 'DNLD15' ;
quit;
proc datasets lib=WORK nolist nodetails;
modify dnld15;
rename
&suffixlist;
run;
You could add another filter to your code:
where libname = 'WORK' and memname = 'DNLD15' and name not in (list) ;
DATA dnld15;
set dnld.2015;
run;
proc sql noprint;
select cats(name,'=',name,'Z')
into :suffixlist
separated by ' '
from dictionary.columns
where libname = 'WORK' and memname = 'DNLD15' and name not in (list) ;
quit;
proc datasets lib=WORK nolist nodetails;
modify dnld15;
rename
&suffixlist;
run;
You could add another filter to your code:
where libname = 'WORK' and memname = 'DNLD15' and name not in (list) ;
DATA dnld15;
set dnld.2015;
run;
proc sql noprint;
select cats(name,'=',name,'Z')
into :suffixlist
separated by ' '
from dictionary.columns
where libname = 'WORK' and memname = 'DNLD15' and name not in (list) ;
quit;
proc datasets lib=WORK nolist nodetails;
modify dnld15;
rename
&suffixlist;
run;
Well, darn. It did rename all but 10 of the variables...but it left those un-renamed variables out of the dataset. How do I keep them in?
Are you dropping somewhere? Can you share your code plz
check the case, ie upper, lower, mixed for variable names or data set name.
@MillerEL wrote:
Well, darn. It did rename all but 10 of the variables...but it left those un-renamed variables out of the dataset. How do I keep them in?
There is nothing in the proposed solutions that would drop any variables.
Show what you did that dropped those variables?
You can get the column name from dictionary.columns too - I can't check the exact field name at the moment but add something like "and colname not in (''ABC", 'DEF')" to your where clause to exclude the listed columns and asuming colname is the field name in dictionary.columns which holds that info.
Yes sorry, i should have mentioned what @ChrisBrooks in the change i made to your code but i was lazy. If you noticed my addition to your where condition, the name column is the column that has a list of variables names in the dictionary.columns metadata. So you can basically filter with IN operator.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.