BookmarkSubscribeRSS Feed
srisoham
Calcite | Level 5

Hi All,

I have below macro code. When i try to execute i am having error.

%macro test;

      %let lb_adt = %str(2011-01-03);

      %let var =  %NRBQUOTE('     ' On %sysfunc(strip(&lb_ADT)) of PCS  %unquote(%do k = 1 %to 3;lb_val&k %end;));

      %put &var;

%mend test;

%test;

Here is log messages:

4095%macro test;
4096%let lb_adt = %str(2011-01-03);
4097%let var =  %NRBQUOTE(' ' On %sysfunc(strip(&lb_ADT)) of PCS  %unquote(%do k = 1 %to 3;lb_val&k %end;));

ERROR: Macro keyword DO appears as text.  A semicolon or other delimiter may be missing.

ERROR: There is no matching %DO statement for the %END. This statement will be ignored.

4098%put &var;

4099   %mend test;

NOTE: The macro TEST completed compilation with errors.

  8 instructions 200 bytes.

4100

4101   %test;

ERROR: Expected close parenthesis after macro function invocation not found.

WARNING: Apparent symbolic reference K not resolved.

NOTE: Line generated by the invoked macro "TEST".

1    lb_val&k));
     ------
     180

ERROR 180-322: Statement is not valid or it is used out of proper order.

I have also tried using the  %unquote and %nrstr to resolve but still having error messages.

%macro test;

      %let lb_adt = %str(2011-01-03);

      %let var =  %NRBQUOTE('     ' On %sysfunc(strip(&lb_ADT)) of PCS  %unquote(%nrstr(%do k = 1 %to 3;lb_val&k %end;)));

      %put &var;

%mend test;

%test;

Here is log for above code:

ERROR: The %DO statement is not valid in open code.

WARNING: Apparent symbolic reference K not resolved.

ERROR: The %END statement is not valid in open code.

'     ' On 2011-01-03 of PCSlb_val&k

I am not sure what kind of mistake i am doing here.  Can someone provide any help?

Srisoham

3 REPLIES 3
Astounding
PROC Star

You're making this problem much more complex than it needs to be.  How about starting this way:

%macro test;

   %local k;

   %global var;

   %do k=1 to 3;

         %let var = &var lb_val&k;

   %end;

   %let var = %str(   On ... &var);

%mend test;

srisoham
Calcite | Level 5

Thank you very much.  This helped me temporarily resolution.  Is there way send the macro instruction resolve it later?

The reason is in the above code, at DO loop the reference range high values are dynamic based the pre information availability.

I want to write it something like

%let txt = %nrbquote( %if &val ^=   %then %do;not missing %end;%else %do missing%end;);

Sri

Astounding
PROC Star

The easiest way uses CALL SYMPUT instead of macro quoting.  That makes it easy to suspend resolution until later.  For example:

data _null_;

call symput('var', 'Some long string that includes &val2';);

run;

Either earlier or later:

%if %length(&val) > 0 %then %let val2=non missing;

%else %let val2 = missing;

Then later on when you need it:

%let txt = &var;

There are other ways, including macro quoting.  This is just the way I would choose.

Good luck.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 3 replies
  • 2459 views
  • 6 likes
  • 2 in conversation