DATA Step, Macro, Functions and more

SAS Variables

Reply
Occasional Contributor
Posts: 6

SAS Variables

Lets assume I have an excel file which has column name starting with a number(ex 2_Addressline). Is it possible to import the file into SAS and use the variable name as it is? if yes how does it work?

Is there any others s/w which creates the column name starting with a numneral and can be used with SAS datastep?
Super Contributor
Super Contributor
Posts: 3,174

Re: SAS Variables

Posted in reply to Anuj_Gupta
SAS variables must start with an alpha-character.

You may find reference information at the SAS support website http://support.sas.com/ using the Google advanced search argument below:

dbms import numeric column variable name site:sas.com

Scott Barry
SBBWorks, Inc.

SAS Language Concepts: SAS Variable Attributes
http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a001103996.htm
PROC Star
Posts: 1,760

Re: SAS Variables

Alternatively, you can set option validvarname to accept any name form, and use the n extension to tell sas the string is a name.

This is valid:
[pre]
option validvarname=any;
data t;
'2@#$%,./;'n = 'a';
run;
[/pre]

Make sure you have a good reason to do this though.
Super Contributor
Posts: 474

Re: SAS Variables

Don't know if it helps, but...

Although SAS variables cannot start with a digit, their labels can.

As some reporting tools use the label instead of the variable name (SAS/VIEW, SAS E/G, etc..) and if this suffices, just use the LABEL statement to associate any text you want to the desired variable.

Check the online documentation for the LABEL statement here:
http://support.sas.com/documentation/cdl/en/lrdict/61724/HTML/default/a000201974.htm

Cheers from Portugal.

Daniel Santos @ www.cgd.pt
Occasional Contributor
Posts: 6

Re: SAS Variables

thanks much..
this helps
Occasional Contributor
Posts: 6

Re: SAS Variables

Thanks a lot, this is the best solution I could have got. Is there any way to assign the values of these columns in some other columns or to do any calculations etc.. Message was edited by: Anuj Gupta
Occasional Contributor
Posts: 6

Re: SAS Variables

Posted in reply to Anuj_Gupta
Hey I found the solution. The columns names starting with numeric are assumed as SAS name literals. To be able to use these variables in datastep we can use following
'variable'n
Ask a Question
Discussion stats
  • 6 replies
  • 177 views
  • 0 likes
  • 4 in conversation