Desktop productivity for business analysts and programmers

Conditional Dataset Creation

Reply
Contributor
Posts: 73

Conditional Dataset Creation

WrninHello EG Users,

I intend to check for variable value before I decide if I would like to append the two datasets.

Pseudocode:

If CurrentDate = PreviousDate + 1 Then append two datasets

Else let user know that there are missing observations for dates from (PreviousDate + 1) through (CurrentDate - 1)

Is it possible to write PROC SQL or DATA APPEND code inside THEN clause of above conditional IF statement. Essentially access two entirely different datasets?

IF CurrentDate = PreviousDate + 1 THEN

PROC SQL

CREATE TABLE WORK.TABLEC

SELECT ActualDate, Total

FROM TABLEA INNER JOIN TABLEB ON ActualDate

ORDER BY ActualDate;

RUN;

ELSE  * Forcibly create empty dataset ;

PROC SQL

CREATE TABLE WORK.TABLEC

SELECT ActualDate, Total

FROM TABLEA OUTER JOIN TABLEB ON ActualDate

ORDER BY ActualDate;

RUN;

TABLEA

ActualDateTotal
01/01/201410
01/02/201420
01/03/201430

TABLEB

ActualDateTotal
01/04/201440

TABLEC

ActualDateTotal
01/01/201410
01/02/201420
01/03/201430
01/04/201440

However if TABLEB contains

ActualDateTotal
01/06/201440

Then I would tell user that observation for 01/04/2014 and 01/05/2014 are missing and will not output appended dataset. Outer Join trick can be used to create empty dataset, just in case it is not possible to have WARNING pop-up.

How can user be notified that there are missing observations for some days and two datasets cannot be appended. Is there way to comment it out into Project Log? or pop-up message

Thanks,

Dhanashree

Super User
Posts: 5,352

Re: Conditional Dataset Creation

Dhanashree,

It looks like your variables are part of a DATA step.  In that case, CALL EXECUTE is the tool for the job:

if CurrentDate = PreviousDate + 1 then call execute ('PROC SQL; CREATE ... first set of code; RUN;');

else do;

   call execute ('PROC SQL; CREATE ... second set of code; RUN;');

   put '**************************************************************************';

   put 'Data Set CANNOT be created';

   put 'Whatever message you would like the user to see in the log.';

   put '**************************************************************************';

end;

stop;

The STOP statement might be necessary if you incoming data set contains more than one observation.  You should generate the proper SQL code and related message only once.

Good luck.

Ask a Question
Discussion stats
  • 1 reply
  • 695 views
  • 0 likes
  • 2 in conversation