NebulousReveal
NebulousReveal

Reputation: 572

Variable Name in SAS

I have a variable name called A_flag (1=Y,0=N) . However, when I try to rename this variable, SAS says that it can't find the variable.

Is the variable name A_flag (1=Y,0=N) or A_flag ?

Upvotes: 1

Views: 641

Answers (2)

Joe
Joe

Reputation: 63424

That is likely a variable label, not a variable name. If you are in display manager SAS (not Enterprise Guide), go into the View menu when you have a dataset open and select "Column Names" instead of "Column Labels". That will show you the real variable name.

If it is a variable name, it probably came in with Enterprise Guide's default setting of options validvarname=any and a proc import from Excel. If that's the case, I suggest adding to either your configuration file or just to the top line of your program:

options validvarname=v7;

Then run the proc import again and it will properly import the name as a legal SAS variable name without the name literal syntax Stig refers to (which is also a fine solution, but it can be tedious to use that.)

Upvotes: 4

Stig Eide
Stig Eide

Reputation: 1062

If the variablename really is "A_flag (1=Y,0=N)", then you need to refer to it as "A_flag (1=Y,0=N)"n. E.g:

proc freq;
    tables "A_flag (1=Y,0=N)"n;
run;

You need the validvarname=any option set in order for this to work.

Upvotes: 5

Related Questions