Escape characters interpreted as array in SAS

2019-08-17 04:12发布

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?

标签: sas
2条回答
一纸荒年 Trace。
2楼-- · 2019-08-17 04:36

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.

查看更多
不美不萌又怎样
3楼-- · 2019-08-17 04:58

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

查看更多
登录 后发表回答