11-23-2017 03:16 AM
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
11-23-2017 03:31 AM - edited 11-23-2017 03:31 AM
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?
11-23-2017 03:35 AM
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;
11-23-2017 03:57 AM
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
11-23-2017 04:41 AM
"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.