BookmarkSubscribeRSS Feed
jos283
Fluorite | Level 6

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!

2 REPLIES 2
ballardw
Super User

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(&param)=,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.

 

So

%if %isblank(Value_2_Items) %then %do;

    /*nothing*/

%end;

%else %do;

And Value_2 in (&Value_2_Items.)

%end;

 

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.

jos283
Fluorite | Level 6

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 2 replies
  • 2300 views
  • 1 like
  • 2 in conversation