Help using Base SAS procedures

Direct my dataset to execute differently

Occasional Contributor
Posts: 12

Direct my dataset to execute differently

I am trying to find out how I can direct my SAS data step to act differently based on different conditions.

For ex: If in my dataset condition is  true then I want my program to not execute any other piece of code and instead  send me an email and if the condition is false then I want SAS to execute the remaining piece of code and not send me an email..

Super User
Posts: 17,912

Re: Direct my dataset to execute differently

Use macro code to control which data steps are executed.

Super Contributor
Posts: 339

Re: Direct my dataset to execute differently

SAS(R) 9.2 Companion for z/OS

Above is about sending e-mails.

I'm guessing that by dataset condition you mean like a property of a dataset and not a variable stored in a row of the dataset but it can technically result in similar approaches. It's difficult without more details about your SAS job but wrapping and nesting the job in a simple data step using if condition with a do block to send e-mail and then stop; statement and and else do block to call execute your wrapped code.

There are probably better solution depending at which point in your process you need to validate that condition whether its an all or nothing or a subtask, etc.

I don't use these features much I'm just a methodologist with a keen interest in programming so I can't provide much more help without you providing far more details. Nonetheless, I hope the above gives you some ideas on how to proceed.


Respected Advisor
Posts: 3,777

Re: Direct my dataset to execute differently

Perhaps you need "Put Statement e-mail directives" .  A bit more detail about the exact process what help too.

FILENAME Statement, EMAIL (SMTP) Access Method :: SAS(R) 9.4 Statements: Reference

Occasional Contributor
Posts: 7

Re: Direct my dataset to execute differently


put your code in a macro and use a %if sentance , i recoment to create a macro to discribe you "true" condition (proc sql) lets assume you want to count a number of rows in the table and if the amount is more than X do a else do b.

for example :

%macro test();

proc sql noprint;

select count(*) into :mnobs1 from y.table;  quit;

%if (&mnobs1.  > 10)   %then %do;

(add you code for the first condition)


%else %do;

(add you code for the seconed condition)




good luck

Super User
Posts: 5,093

Re: Direct my dataset to execute differently

In addition to reading data_null_'s reference about how to send an email, you will also have to provide a little more detail on what should happen.

A data set condition can be true on one observation, and false on another.  In fact, it could be true on many observations, and false on many others.  What should happen?  How many emails do you want to receive?  Give us some idea of what you are checking as your "data set condition" and how you know whether it is true or false.

Regular Contributor
Posts: 200

Re: Direct my dataset to execute differently

1. A macro is, yes, the first solution

2. Here is the basic open-code syntax


,%nrstr(*trueSmiley Wink

,%nrstr(*falseSmiley Wink


Ron Fehd  sysfunc+ifc maven

Ask a Question
Discussion stats
  • 6 replies
  • 7 in conversation