Hi there, I faced big issues when I discovered that my variable names were containing carriage return in it. The problem is that when your variables names contains carriage return, it is possible to call the variables with a KEEP statement but when you want to call a specific variable, SAS will not read correctly the request. . For example if your variable name is WO
K the following code will indeed read correctly the request: data want;
set have;
keep w:;
run; and that code will then not work: data want;
set have;
wok="WO
K"N;
run; It is then not possible to rename the variables since SAS is not capable of reading it. I worked a lot to find a solution that finally was not that complicated. I wanted then to share it with you if ever, you had to manage variables names with carriage return in it. So here is the macro that will manage it:
%macro carriage /*Macro that drop carriage returns from variable names*/
(lib /* Specify library*/,
data /*Specify dataset*/,
out /*Specify output dataset (mandatory in order to not erase proper data*/,
vars /*Specify variables to rename*/);
data &lib..&out;
set &lib..&data;
keep &vars;
run;
data &lib..&data;
set &lib..&data;
drop &vars;
proc transpose
data=&lib..&out
out=&lib..&out;
run;
data &lib..&out;
set &lib..&out;
_NAME_=compress(_NAME_,'0D0A'x);
run;
proc transpose
data=&lib..&out
out=&lib..&out(drop=_name_);
run;
data &lib..&data;
merge &lib..&data &lib..&out;
run;
%mend carriage;
Have a good day, Nathan
... View more