BookmarkSubscribeRSS Feed
noobs
Fluorite | Level 6

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

1 REPLY 1
Astounding
PROC Star

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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1835 views
  • 0 likes
  • 2 in conversation