BookmarkSubscribeRSS Feed
mj5
Obsidian | Level 7 mj5
Obsidian | Level 7

 

Hi,

I am trying to do the below code

 

 

%let oth=Other;

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

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

4 REPLIES 4
Kurt_Bremser
Super User

Just resolve the macro variable yourself:

data test;
   if Other ne "" then Other;
run;

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

What are you trying to achieve?

mj5
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;

Kurt_Bremser
Super User

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

You set macro variable oth to the value

Other

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

Other

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

Other

???

RW9
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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 834 views
  • 0 likes
  • 3 in conversation