Desktop productivity for business analysts and programmers

SAS MACRO VARIABLE

Accepted Solution Solved
Reply
Contributor
Posts: 70
Accepted Solution

SAS MACRO VARIABLE

I am facing some issues in SAS Macro Variables.

 

I have a program in which my library name is a macro variable and the data set name may or may not be a macro variable.

 

something like this . >

 

&LIBRARY.SORTED,

 

or 

 

&LIBRARY.&DATA

 

now whenever I use it as &LIBRARY.SORTED, It resolves to SASHELPSORTED and considers it to be in work library.

 

what should I do to resolve it as SASHELP.SORTED


Accepted Solutions
Solution
‎07-15-2017 03:52 AM
Super User
Super User
Posts: 7,720

Re: SAS MACRO VARIABLE

You should learn the full syntax for using a macro variable and Always use it in your code.  The form is:

&<macro variable name>.

 

Note the & before and the dot afterwards, this is the leading and terminating character, so when you use the dot it terminates the variable, and does not show in the generated text.  What your code should look like (and also note that coding all in upper case makes it harder to read):

&library..sorted

 

You will see the two dots, one to close the macro variable, the second is used to delimit library and dataset.

View solution in original post


All Replies
Super User
Posts: 7,446

Re: SAS MACRO VARIABLE

Macro variable names muste be valid SAS names (letters, digits, underlines, must not start with a digit, max length 32). The dot cannot be used in a macro variable name; it is always used to mark the end of a macro variable name when it is referenced.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Solution
‎07-15-2017 03:52 AM
Super User
Super User
Posts: 7,720

Re: SAS MACRO VARIABLE

You should learn the full syntax for using a macro variable and Always use it in your code.  The form is:

&<macro variable name>.

 

Note the & before and the dot afterwards, this is the leading and terminating character, so when you use the dot it terminates the variable, and does not show in the generated text.  What your code should look like (and also note that coding all in upper case makes it harder to read):

&library..sorted

 

You will see the two dots, one to close the macro variable, the second is used to delimit library and dataset.

Contributor
Posts: 70

Re: SAS MACRO VARIABLE

ThankYou Very Much EveryOne. It worked. Smiley Happy

Super User
Posts: 19,167

Re: SAS MACRO VARIABLE

&LIBRARY..&DATA

You need two periods.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 235 views
  • 0 likes
  • 4 in conversation