I am using SAS university edition.
I want to have a variable named "Age(years)" instead of "Age_years" for the following data set. I understand that "()" will be interpreted as array, while I need this to be a part of the variable.
data data;
input Name $ Age_years Gender $;
datalines;
Dino 6 male
Rita 5 female
Aurora 6 female
Joko 7 male
;
run;
The exact error when I am accessing the following line is " ERROR: Undeclared array referenced: Age.
ERROR: Variable Age has not been declared as an array."
data data;
set data;
Age(years)=Age_years;
run;
I have checked for possibility of escaping this bracket characters so that it won't be interpreted as array as in here : Special Characters in SAS however the % symbol does not help to escape the () characters. How can I do this in SAS?
You could call that 'n' a modifier. There are a few you can append to the end of a quoted literal to specify how SAS should treat it:
'my variable'n
will be treated as a variable called 'my variable'
'14AUG2017'd
will be treated as a number representing today's date
'14AUG2017:09:53:00'dt
will be treated as a number representing today's date and time
'49'x
will be treated as the letter A, here specified by its hexadecimal value.
...and others I may have forgotten.
Note that it is not considered good practice to use non SAS-valid names.
EDIT: link to SAS support
Ok, I missed some hints from other SO links.
SAS: how to use the table column with special character $
How I solved this is with the following
option validvarname=any;
data data;
'Age(years)'n = Age_years;
run
Thing is I do not understand what does "n" above actually means, because if I remove it, Age(years) will mean string.