BookmarkSubscribeRSS Feed
noobs
Calcite | Level 5

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 1 reply
  • 1458 views
  • 0 likes
  • 2 in conversation