07-25-2017 05:13 PM
This is the code I created, and it will stop running if it reaches a line where a macro is unassigned.
Data New; Set Old; If Value_1 in (Value_1_Items.) And Value_2 in (Value_2_Items.) And Value_3 in (Value_3_Items.) Then Output; Run;
If a variable is blank/unassigned (lets say Value_2_Items.) , then I want the code to skip this line and to continue running the other macros.
Any ideas on how I would go about fixing my code? Thanks!
07-25-2017 05:39 PM - edited 07-27-2017 11:28 AM
You might want to provide a more concrete example of some actual data that would 1) do the skip and 2) not do the skip.
And since there isn't any macro code OR macro variables shown it would help to show where this step lies in relation to the remaining code and indicate where in the macro code the execution would continue.
You imply that any of the Value_1 etc items may be unassigned. What should happen if all of then are unassigned? What if the first is unassigned?
Here is a small macro that can be used to check if a macro variable does not have anything assigned that I cribbed from someone on this forum awhile ago:
%macro isBlank(param); %sysevalf(%superq(¶m)=,boolean) %mend isBlank;
/* edited to add missing &*/
It returns 1 for yes it is blank, 0 for no it is not blank. This could be used inside another macro as:
%if %isBlank(sysdate) %then %put SYSDATE is Blank.
Note that the NAME of the macrovariable is passed, not with &sysdate.
If the macrovariable does not exist then you get a warning that the macro ISBLANK did not resolve.
%if %isblank(Value_2_Items) %then %do;
And Value_2 in (&Value_2_Items.)
for your specific example.
You will need to address that the inital IF in you data step versus AND bits for the subsequent variables if &Value_1_Items is blank.
07-25-2017 06:41 PM - edited 07-25-2017 06:42 PM
Okay, here's an example that should help provide more information.
Let's say Value_1_Items. = "Happy", "Sad"
In this case, the code should output a database called "New" showing data consisting of all "Happy" and "Sad" values that exist in Column "Value_1" from the database "Old".
Value_1_Items (same applies for Value_2_Items etc.) can be = "one string" in length
or = "two", "strings" (as seen with "Happy", "Sad" above)
or = more (like a list, if you get what I'm trying to say).
If all are unassigned, then there would be no output as there is nothing to run or find from database "Old" under the columns Value_1, Value_2, or Value_3.
If the first is unassigned, the code should ignore Value_1 and continue with Value_2 and Value_3 and output data that they contain from database "Old".
Therefore, I don't want to run a check because I just want the code to continue to run smoothly/automatically regardless of if one or two items are missing an assigned variable(s).