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
ActualDate | Total |
---|---|
01/01/2014 | 10 |
01/02/2014 | 20 |
01/03/2014 | 30 |
TABLEB
ActualDate | Total |
---|---|
01/04/2014 | 40 |
TABLEC
ActualDate | Total |
---|---|
01/01/2014 | 10 |
01/02/2014 | 20 |
01/03/2014 | 30 |
01/04/2014 | 40 |
However if TABLEB contains
ActualDate | Total |
---|---|
01/06/2014 | 40 |
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
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.
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.
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.