DATA Step, Macro, Functions and more

Macro quoting

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 87
Accepted Solution

Macro quoting

I have a macro variable:

%let xcesint = '20121131'; (gives no issues)

%let xcesint = %str(%')%sysfunc(intnx(year,&mydate,-1,end),yymmddn8.)%str(%'); (gives issues as below)

*******************************************LOG*************************************************************************************

2744      +data xcsint2&tapein&version;
SYMBOLGEN:  Macro variable TAPEIN resolves to OlsBeliz
SYMBOLGEN:  Macro variable VERSION resolves to
2745      +  set xcsint&tapein&version;
2746      +  xcsint   = amtinfrc;
2747      +  xcsintdt = &xcesint;
SYMBOLGEN:  Macro variable XCESINT resolves to '20111231'
SYMBOLGEN:  Some characters in the above value which were subject to macro quoting have been unquoted for printing.

           _
           _
           _
           386
           386
           386
            ________
            ________
            ________
            200
            200
            200
ERROR 386-185: Expecting an arithmetic expression.
ERROR 386-185: Expecting an arithmetic expression.
ERROR 386-185: Expecting an arithmetic expression.

66                                                                                                     The SAS System                                                                         16:28 Thursday, March 14, 2013

ERROR 200-322: The symbol is not recognized and will be ignored.
ERROR 200-322: The symbol is not recognized and will be ignored.
ERROR 200-322: The symbol is not recognized and will be ignored.

***********************************************************************************************************************************************************

Though both the variables are resolving to same value why is my second attempt failing?


Accepted Solutions
Solution
‎03-14-2013 05:15 PM
Super User
Posts: 5,083

Re: Macro quoting

Here's the likely missing link:

%let xcesint = %unquote(the exact same value being assigned now);

SAS's message indicates that it hasn't figured out soon enough that it should be unquoting the special characters in your assigned value.  So just apply %unquote yourself.

As a side note, I would guess it's safer to remove the dot at the end of the format when using %sysfunc:  yymmddn8

Good luck.

View solution in original post


All Replies
Solution
‎03-14-2013 05:15 PM
Super User
Posts: 5,083

Re: Macro quoting

Here's the likely missing link:

%let xcesint = %unquote(the exact same value being assigned now);

SAS's message indicates that it hasn't figured out soon enough that it should be unquoting the special characters in your assigned value.  So just apply %unquote yourself.

As a side note, I would guess it's safer to remove the dot at the end of the format when using %sysfunc:  yymmddn8

Good luck.

Valued Guide
Posts: 632

Re: Macro quoting

It has been my experience that storing quotes with a macro variable is very very rarely either necessary or a good idea.  You can always add them when needed at resolution time.

We cannot see what your &MYDATE contains, but the code indicates that it is a SAS date value and not a date form as is &XCESINT.

%let mydate = 18945;

%let mydate2 = %sysfunc(putn(&mydate,yymmddn8 ));

%let xcesint = %sysfunc(intnx(year,&mydate,-1,end),yymmddn8.);

%put &mydate2 &xcesint;

☑ This topic is SOLVED.

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

Discussion stats
  • 2 replies
  • 650 views
  • 5 likes
  • 3 in conversation