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
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?
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;
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
???
"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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.