BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
vittorio_giatti
Fluorite | Level 6

Hi Everyone. 

 

Lately I got to deal with the folliwing issue. I am wondering if there is any SAS inhabitant able to figure a way out of that. It's simple, but not easy. 

This was the last practical question of the "SAS Certified Professional: Advanced Programming Using SAS 9.4".

 

Program:

%macro Test();
  %put ERROR: Do not print;

  proc print data=sashelp.cars;
  run;
%mend;

options /* **??** */;
%Test();

 

Log

dddddddd.JPG

 

The description was very clear:

 

"It's not possible to add anything else to the macro program. How do we make the program execute without errors?"

I am wondering if there is an option (on errors or macro) to avoid it. I already tried a few, but it still makes my brain wrecking.

 

Thanks. Regards. 

Vittorio

1 ACCEPTED SOLUTION

Accepted Solutions
gamotte
Rhodochrosite | Level 12

Hello,

 

I completely agree with @PaigeMiller but i tried to find a solution anyway :

 

filename tf temp;

proc printto log=tf;
run;

%macro Test();
  %put ERROR: Do not print;

  proc print data=sashelp.cars;
  run;
%mend;

proc printto log=log;
run;


data errorless;
infile tf;
input;
retain out 0;

code=prxchange("s/^\d+ //",1,_INFILE_);

if strip(upcase(code))=:'%MACRO' then out=1;
if out and strip(upcase(code)) ne: '%PUT ERROR' then output;
if strip(upcase(code))=:'%MEND' then out=0;
run;

data _NULL_;
set errorless;
call execute(code);
run;

View solution in original post

15 REPLIES 15
PaigeMiller
Diamond | Level 26

I don't see a problem with your code or the results. SAS is doing exactly what the macro says it should do. The fact that the log contains an error statement is because you (or someone) programmed the macro to write

ERROR: Do not print

to the log.

 

So, what is the problem?

--
Paige Miller
vittorio_giatti
Fluorite | Level 6
The macro program should execute the proc print and not show the error in the log!
Most likely there is an option for that.

Maybe there is no solution and the question was wrong!
PaigeMiller
Diamond | Level 26

But the macro specifically writes the text "ERROR: Do not print" to the log. That is the first line under %MACRO. That is what the macro was designed to do. If you don't want it to do that, change the macro. You are the programmer, you have complete control over what the macro does.

--
Paige Miller
vittorio_giatti
Fluorite | Level 6

That was the exam question. "It's not possible to add anything else to the macro program". 

If I modify the program, the evaluation points are ZERO. 

 

I don't think you get the question.

Of course you can to modify the code. Here is not possible!!!!!!!!!!!!!!!!!!

 

We have a sort of constraint that I found myself bumping up against. Again: it's an exam question.

vittorio_giatti
Fluorite | Level 6
As I said, maybe that was a BUG of the exam. As far as I got from your answers, that's what you also think. Thanks
PaigeMiller
Diamond | Level 26

So we find ourselves in an absurd situation where the code doesn't do what we want, but we are not allowed to change the code.

 

By the way, when you say "It's not possible to add anything else to the macro program", I point out that the solution I am proposing, to remove the line of code that we don't want, does not ADD anything else to the macro program. It SUBTRACTS code from the program. Seems to me that is okay according to the directive: "It's not possible to add anything else to the macro program".

--
Paige Miller
vittorio_giatti
Fluorite | Level 6
No, the program should be that. It can't be CHANGED, that's the meaning.
PaigeMiller
Diamond | Level 26

Then I choose to leave this discussion, as the exam question is absurd, and not worth more of my time. I wish you good luck in finding an answer.

--
Paige Miller
RichardDeVen
Barite | Level 11

The program is the entire source code.  The macro program is the section of the macro code that defines the macro Test.

 

How do we make the program execute without errors?

The program is already executing correctly as coded without actual errors.  The macro program has been coded to write a message (starting with ERROR:) to the log.

 

If the inferred task is to change the program but not the macro program would you go 'meta' and look at the macro %PUT message ?  The message is telling you to DO NOT PRINT.  Based on the 'meta' analysis I would say simply comment out the macro invocation.

%*Test();

No error message ! No printing !

 

Agree with @PaigeMiller "the exam question is absurd"

vittorio_giatti
Fluorite | Level 6

It is not allowed to modify the macro program.

 

Recalling that macro, the result should be: 

1) no error message 

2) proc print (from the sas program) prints 

 

None of the exam answer was so dumb: there is an option or the question was wrong (it's not a new). 

vittorio_giatti
Fluorite | Level 6
*
2) proc print (from the sas macro program) prints
PaigeMiller
Diamond | Level 26

"It's not possible to add anything else to the macro program. How do we make the program execute without errors?"

 

In SAS, highlight this part of the code and then just execute this:

  proc print data=sashelp.cars;
  run;

Thus, we haven't changed the program, every single line of the program still is intact, but we get the desired output.


If that is the correct answer, the person who created this question should be ashamed. And if this answer is correct, this defeats the purpose of having a macro, and it defeats the purpose of programming in general.

 

--
Paige Miller
Quentin
Super User

I agree with others, it's likely an error in the question (or just a bad question).

 

Unless there is a system option to turn off %PUT statements (I don't think there is), I can't imagine what would be a good answer to this question.

 

Since it's apparently a question from a SAS book or online test prep guide, I'd recommend you submit it to the publisher as an erratum.  I'd be curious how they respond, please let us know.

BASUG is hosting free webinars Next up: Mike Sale presenting Data Warehousing with SAS April 10 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
gamotte
Rhodochrosite | Level 12

Hello,

 

I completely agree with @PaigeMiller but i tried to find a solution anyway :

 

filename tf temp;

proc printto log=tf;
run;

%macro Test();
  %put ERROR: Do not print;

  proc print data=sashelp.cars;
  run;
%mend;

proc printto log=log;
run;


data errorless;
infile tf;
input;
retain out 0;

code=prxchange("s/^\d+ //",1,_INFILE_);

if strip(upcase(code))=:'%MACRO' then out=1;
if out and strip(upcase(code)) ne: '%PUT ERROR' then output;
if strip(upcase(code))=:'%MEND' then out=0;
run;

data _NULL_;
set errorless;
call execute(code);
run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 15 replies
  • 1577 views
  • 7 likes
  • 5 in conversation