BookmarkSubscribeRSS Feed
RedUser77
Obsidian | Level 7

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;

8 REPLIES 8
PeterClemmensen
Tourmaline | Level 20

Post your log please.

RedUser77
Obsidian | Level 7

2022-11-23_08h46_50.png

 Not able to reveal whole log as it is sensitive.

ChrisHemedinger
Community Manager

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.

SAS Hackathon registration is open! Build your skills. Make connections. Enjoy creative freedom. Maybe change the world.
PeterClemmensen
Tourmaline | Level 20

What does the macro variable &faxes resolve to?

RedUser77
Obsidian | Level 7

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.

PeterClemmensen
Tourmaline | Level 20

Are you sure that the %let Statement has always referenced &FAXES? What is the point of that?

RedUser77
Obsidian | Level 7

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. 

ChrisHemedinger
Community Manager

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 Hackathon registration is open! Build your skills. Make connections. Enjoy creative freedom. Maybe change the world.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

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
  • 8 replies
  • 554 views
  • 1 like
  • 3 in conversation