DATA Step, Macro, Functions and more

How to prevent macro resolution in open code

Accepted Solution Solved
Reply
Contributor
Posts: 65
Accepted Solution

How to prevent macro resolution in open code

I have a macro variable named &_badFileName.  It contains the value &cmpn_cd_YYYYMMDD_TEST_DONT_LOAD.  The code runs in open code, not a macro.

I need to print the text vallue of the macro variable in an error message _without_ the value of &cmpn_cd being resolved.  I want to see the string &cmpn_cd_YYYYMMDD_TEST_DONT_LOAD in my error message.

I've tried all of the quoting function I can think of.

I've tried nesting some of the functions.

I've tried using quoting functions in a %let statement to reassign the value of &_badFileName there instead of in the putlog statement.

But they either try to resolve &_badFileName and return the Error seen below below or prevent resolution of &_badFileName so that &_badFileName prints in the message as text.

It seems to me that I need a quoting function that masks resolution at execution.  I'm sure I'm missing something simple, but Help will be greatly appreciated.  Thanks in advance.

 

9707 data _null_;

19708 putlog '-----';

19709 putlog "USER-DEFINED ERROR: At least 1 Output File Name in the &_excelWorkbookName Output_Fields worksheet is

19709! bad.";

19710 putlog ' It must contain a valid date formatted as YYYYMMDD.';

19711 putlog " The bad Output File Names are %nrbquote(&_badFileNames)..";

ERROR: Symbolic variable name CMPN_CD_YYYYMMDD_TEST_DO_NOT_LOAD must be 32 or fewer characters long.

19712 putlog '-----';

19713 run;

run;


Accepted Solutions
Solution
‎02-26-2015 02:09 PM
Super User
Posts: 5,099

Re: How to prevent macro resolution in open code

Have you tried:

putlog " The bad Output File Names are %superq(_badFileNames).";

Note that the & is removed ... it's supposed to be that way.

Good luck.


View solution in original post


All Replies
Respected Advisor
Posts: 3,908

Re: How to prevent macro resolution in open code

data _null_;

  call symputx('_badFileName','&cmpn_cd_YYYYMMDD_TEST_DONT_LOAD');

  stop;

run;

data _null_;

  badfile=symget('_badFileName');

  putlog "The bad Output File Names are " badfile;

  stop;

run;

...or this way:

data _null_;

  putlog "The bad Output File Names are %superq(_badFileName)";

  stop;

run;

Contributor
Posts: 65

Re: How to prevent macro resolution in open code

Astounding, that's it!!   %SUPERQ() doesn't want the & for the macro variable.  I knew I was missing something simple.

Patrick, Thanks for a workable second solution.  Sometimes I get so fixated on a specific solution that I don't stop, take a breath, and consider alternatives.  If I could give you both Correct Answer credit I would, but Astounding was first by a few minutes.

John

Super User
Posts: 3,115

Re: How to prevent macro resolution in open code

If you really must have the &:

%let _badFileName = %nrstr(&cmpn_cd_YYYYMMDD_TEST_DONT_LOAD);

data _null_;

putlog "&_badFileName";

run;

Solution
‎02-26-2015 02:09 PM
Super User
Posts: 5,099

Re: How to prevent macro resolution in open code

Have you tried:

putlog " The bad Output File Names are %superq(_badFileNames).";

Note that the & is removed ... it's supposed to be that way.

Good luck.


🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 366 views
  • 3 likes
  • 4 in conversation