BookmarkSubscribeRSS Feed
Obsidian | Level 7 mj5
Obsidian | Level 7



I am trying to do the below code



%let oth=Other;

data test;
   if &oth ne "" then &oth;

I am not sure what the varible name will be for oth and need to make it optional so that if there is variable present then use it else not use.


Somehow this program logic doesnt work. Am i missing something. Please advice

Super User

Just resolve the macro variable yourself:

data test;
   if Other ne "" then Other;

and you will see that the code is syntactically invalid and makes no sense at all.

What are you trying to achieve?

Obsidian | Level 7 mj5
Obsidian | Level 7

I am trying to make a macro variable oth and not sure what the variable name will be for it. and then later in the datastep want to make sure if the variable exists and has no missing observation then assign the macro variable the variable name which will exist

%let oth=other; in case the variable name is other. 


if other ne "" then &oth=other;

Super User

Following your logic, you do exactly nothing, in a quite complicated way:

You set macro variable oth to the value


Then you check if data step variable "other" is not missing, in which case you again set the macro variable oth to


and if not existing or missing, you do nothing, so &oth will keep its value, which is



Diamond | Level 26 RW9
Diamond | Level 26

"and then later in the datastep want" - macro language is a separate component from datastep language.  Datastep language is the programming language of SAS, macro is an additional textual find and replace system which can help generate datastep code.  The to do not work together, but on after the other, so your statement above can never be done.  Describe your problem, start with some test data, and what you want out at the end.  There are many ways to find out if a variable is missing, however it isn't that often you would need to change your code physically based on this assumption.


Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.


Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 3 in conversation