how to continue a task based on the output value

Reply
Contributor
Posts: 44

how to continue a task based on the output value

hi all,

I am working on a program where the intial program out put provides data  from the database.

The output is similar to :

26JUN2014         205      7167

27JUN2014       27490    4657

28JUN2014       16690    7881

I want to write a code which continues with the program ,if the output contains 01JUL2014  or else send an email advising that no Data available after 28JUN2014.

please help

Moderator
Posts: 238

Re: how to continue a task based on the output value

Hi Boin,

How you intend to run the program will affect which solution is best.

For example:

  • Base/SAS code: Place the whole code within a macro program, and use a conditional %if to control which code gets processed.
  • Enterprise Guide: Set up a condition on subsequent tasks based on a previous task
  • Data Integration Studio: Various transformations to control processing within a job
  • Process Manager: Use the results of a previous job to control which subsequent jobs are run.
  • etc.

If you can provide more information on how the program will be run, we can narrow down the better choices.

Regards,

Andrew.

Contributor
Posts: 44

Re: how to continue a task based on the output value

Hi Andrew,


I am planning to run the program in SAS EG and SAS DI Studio.

Steps in these will be helpful.

Kind Regards

Shiva

Super Contributor
Posts: 297

Re: how to continue a task based on the output value

Hi Boin,

The following should do what you are after.  You just need to replace the macro variables with the code you wish to execute.

PROC SQL NOPRINT;

SELECT DISTINCT MAX(DATES) INTO : MAX_DATE

FROM HAVE;

QUIT;

%MACRO TEST;

  %IF %SYSFUNC(TODAY()) = &MAX_DATE. %THEN %DO;

  %LET CONTINUE = ADD CONTINUE CODE HERE;

  %END;

  %ELSE %DO;

  %LET EMAIL = INSERT EMAIL CODE HERE;

  %END;

  %PUT &EMAIL. &CONTINUE;

%MEND;

%TEST;

Contributor
Posts: 44

Re: how to continue a task based on the output value

Hi Scott,

I tried to use the code you have provided ,however no luck.

Below is the code i am working with at the moment.

proc sql;

      create table LATT as
         select act_id,
     Eff_Dt,
    chrg_am,
    due_am,
    _bal_am
   

from  rtt_Hist
where Eff_Dt GE '2014/06/01'
     
quit;
proc freq data=LATT;
tables Eff_Dt / norow nocol nopercent;
run;

The above code gives an output of

.........

........

26JUN2014         205      7167

27JUN2014       27490    4657

28JUN2014       16690    7881

******** The below  program has to kick in if the dates are greater than 28JUN2014 or else send out an email.*********

proc sql;  /     
      create table SET1 as
         select act_id,
    
     Eff_Dt,
    chrg_am,
    due_am,
    _bal_am
   

from  rtt_Hist
where Eff_Dt GT '2014/06/22' and Eff_Dt LE '2014/06/23' /*and Eff_Dt LE '2013/08/30'*/
      );
quit;

Super Contributor
Posts: 297

Re: how to continue a task based on the output value

Hi Boin,

You just needed to change some of the values to reflec your data,  Since you didn't provided variable names I used arbitrary names.

From what I can tell you are only carrying out the PROC FREQ to roll up the multiple values contained within EFF_DT.  If this is the case then it is no longer required as we can query the table\dataset directly using PROC SQL SELECT MAX(EFF_DT) INTO : MAX_DATE. This will place the unique maximum value from the variable EFF_DT and use it to create the macro variable MAX_DATE.

I don't have my SAS session set up to send emails, so that portion of the below code is untested and therefore commented out.

Please let me know if any of the code requires further explanation.

Regards,

Scott

OPTIONS MPRINT MLOGIC SYMBOLGEN;

DATA RTT_HIST;

INFILE DATALINES;

LENGTH EFF_DT $10;

INPUT ACT_ID EFF_DT $ CHRG_AM DUE_AM _BAL_AM;

DATALINES;

1 2014/06/26 205   7167  1

2 2014/06/27 27490 4657  2

3 2014/06/28 16690 7881  3

4 2014/07/01 16690 7881  4

;

RUN;

PROC SQL NOPRINT;

SELECT DISTINCT MAX(EFF_DT) INTO : MAX_DATE

FROM RTT_HIST;

QUIT;

%MACRO TEST;

  %IF %SYSFUNC(TODAY()) = %SYSFUNC(INPUTN(&MAX_DATE.,YYMMDD10.)) %THEN %DO;

  PROC SQL;      

  CREATE TABLE SET1 AS

  SELECT ACT_ID,

  EFF_DT,

  CHRG_AM,

  DUE_AM,

  _BAL_AM

   

  FROM RTT_HIST

  WHERE EFF_DT GT  '2014/06/22' AND EFF_DT LE '2014/06/23' /*AND EFF_DT LE '2013/08/30'*/

  ;

  QUIT;

  %PUT "CONTINUE";

  %END;

  %ELSE %DO;

  %PUT "EMAIL";

/* FILENAME EML EMAIL  TO = ("TO@SOMEONE.COM.AU" )*/

/*   SUBJECT =  "SUBJECT";*/

/* DATA _NULL_;*/

/* FILE EML;*/

/* PUT "EMAIL TEXT"; */

/* RUN;*/

  %END;

%MEND;

%TEST;

Contributor
Posts: 44

Re: how to continue a task based on the output value

Thanks Scott, this helps..

Super User
Super User
Posts: 7,392

Re: how to continue a task based on the output value

Pinching Scott_Mitchell's test data, you could also write the code per:

data b;

  set rtt_hist end=last;

  if input(eff_dt,yymmdd10.)='01JUL2014'd then flag=1;

  if last then do;

    if flag=. then call execute('filename eml email to=("TO@SOMEONE.COM.AU");');

    else call execute('data want; set rtt_hist; run;');

  end;

run;

Super User
Posts: 6,928

Re: how to continue a task based on the output value

At the start of your job/program:

%let ref_date='01jul2014'd;

%let continue_flag=NO;

In the data step that creates your "output" data (assuming that the dates are in a numeric variable called date that contains dates according to the SAS convention):

if date=&ref_date then call symput("continue_flag","YES");

After that

%macro continue_code;

%if "&continue_flag"="YES" %then %do;

(insert your code here)

%end;

%mend;

%continue_code;

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Ask a Question
Discussion stats
  • 8 replies
  • 428 views
  • 6 likes
  • 5 in conversation