How to define length in data step for char variable where the variable name contains special character '+' ?
I want to concatenate two datasets (A and B). When i try doing, the values in DTH + RB variables gets truncated due to different length of the variable in two datasets. Hence, I am trying to define the length for variable DTH + RB while concatenating but because of the special character in the variable DTH + RB the below codes are not working.
Can you please suggest how to handle this special characters which are in variable names?
eg: A dataset
ID DTH + RB
1 a
2 abc
3 jeremiahpaul
4 58
5 99
eg: B dataset
ID DTH + RB
1 ab
2 abcd
3 jerereremhihahdjh
4 58
5 99
When i try the below code, sas separates the DTH and RB as different column
data ex;
length DTH + RB $17.;
set A B;
run;
Under the option VALIDVARNAME=ANY, you can use (almost) any characters in variable names, but you need to use so-called "name literals" to address those variables:
length 'DTH + RB'n $17.;
But it is preferred to rename such variables to valid SAS names like dth_plus_rb, as these are much easier to use in further coding:
data ex;
length 'DTH + RB' $17.;
set A B;
rename 'DTH + RB'=dth_plus_rb;
run;
Under the option VALIDVARNAME=ANY, you can use (almost) any characters in variable names, but you need to use so-called "name literals" to address those variables:
length 'DTH + RB'n $17.;
But it is preferred to rename such variables to valid SAS names like dth_plus_rb, as these are much easier to use in further coding:
data ex;
length 'DTH + RB' $17.;
set A B;
rename 'DTH + RB'=dth_plus_rb;
run;
Hello,
This is not a valid SAS variable name. SAS has an option to deal with non valid variables
names but the best solution would be to rename your column.
Not tested :
options validvarname=any;
data ex;
length 'DTH + RB'n $17.;
set A B;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.