BookmarkSubscribeRSS Feed
path2success
Fluorite | Level 6

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

6 REPLIES 6
Reeza
Super User

Use macro code to control which data steps are executed.

Vince28_Statcan
Quartz | Level 8

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.

Vincent

data_null__
Jade | Level 19

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

hi

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)

%end;


%else %do;

(add you code for the seconed condition)

%end;

%mend;

%test();

good luck

Astounding
PROC Star

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.

Ron_MacroMaven
Lapis Lazuli | Level 10

http://www.sascommunity.org/wiki/Using_Functions_SYSFUNC_and_IFC_to_conditionally_execute_statements...

1. A macro is, yes, the first solution

2. Here is the basic open-code syntax

%sysfunc(ifc(&condition

,%nrstr(*true;)

,%nrstr(*false;)

))

Ron Fehd  sysfunc+ifc maven

sas-innovate-2024.png

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.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 6 replies
  • 937 views
  • 0 likes
  • 7 in conversation