Hello, below is a sample query that runs in DB2. However, all of a sudden, I am now getting a prepare error and cannot figure out why. Any ideas? The pasted code can be found below:
/*%put &FAXES;*/
%let FAXES=&FAXES, 1, 2;
/*%put &FAXES;*/
PROC SQL;
(SELECT a.CAR_ID, c.CAR_NAME AS NAME, e.MAKE||' '||e.MODEL AS MAKE_MODEL
FROM OWNER.FACTORY b
LEFT JOIN OWNER.CARS a ON b.KEY=a.KEY
LEFT JOIN OWNER.STATUSES c ON b.TIME_ID =c.TIME_ID
LEFT JOIN OWNER.DRIVERS e ON b.NAME=e.NAME
INNER JOIN (SELECT ENTITY, max(TIME) AS TIMESTAMP
FROM OWNER.FACTORY
WHERE FAX_ID='Fax'
AND ENTITY IN(&FAXES)
AND TIMESTAMP>DATE-60
GROUP BY ENTITY) d ON b.KEY=d.ENTITY AND b.TIMESTAMP=d.TIMESTAMP
WHERE b.FAX_ID='Fax' AND b.KEY IN(&FAXES) AND b.TIMESTAMP>DATE-60);
Quit;
Post your log please.
Not able to reveal whole log as it is sensitive.
Difficult to diagnose without a log, but if it was working and now isn't, I'd check to make sure &FAXES contains what you expect.
What does the macro variable &faxes resolve to?
It is supposed to append dummy keys to the list to prevent errors on 0 or 1 car cases in the report. There is an error with this too all of a sudden where its log reads 'the text expression &FAXES, 1, 2 contains a recursive reference to the macro variable FAXES. The macro variable will be assigned the null value.'
Again, never seen this before as the program has always ran error-free until today.
Are you sure that the %let Statement has always referenced &FAXES? What is the point of that?
Yes, very positive. Been running this since June without any changes ever being made. The point of the variable is to append dummy keys to the list to prevent errors on 0 or 1 car cases in this recurring report.
If FAXES was supposed to have been defined in a previous step, but sometimes isn't, then you need some error checking for defensive programming.
%if %symexist(faxes) %then %do;
%let faxes = &faxes, 1, 2;
%end;
%else %do;
%let faxes = 1, 2;
%end;
%put &=faxes;
You might have a bigger problem going on here with previous steps failing.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.