macro variable

Reply
Frequent Contributor
Posts: 115

macro variable

I am using below code to pass the macro variable in loop.
macro variable 'CUSTOMER_DESC' contains At&t after read the data from sas dataset.


%macro createSlideType3;
options symbolgen;

%macro  mrp_sdc(orgid=,
                    orgnm=
                    );

title " #3A - &orgnm.";


%mend;

%mrp_sdc;

%let CU_NOOFROWS = 0;

data xx;
set temp.cus end=CU_LASTOBS;
call symput("CUID" || strip(put(_n_,best.)), CUSTOMER_CD);
call symput("CUNM" || strip(put(_n_,best.)), CUSTOMER_DESC);

if CU_LASTOBS then
call symput("CU_NOOFROWS", _n_);
run;

/* Run the macro mrp_sdc for each CU */
%macro cu_loop;
%do x=1 %to &CU_NOOFROWS;
%mrp_sdc(orgid=&&CUID&x, orgnm=%quote(&&CUNM&x));
%end;
%mend;
%cu_loop;

%mend createSlideType3;

%createSlideType3;


Result:

SYMBOLGEN:  Macro variable CU_NOOFROWS resolves to            1
SYMBOLGEN:  && resolves to &.
SYMBOLGEN:  Macro variable X resolves to 1
SYMBOLGEN:  Macro variable CUID1 resolves to 100002             
SYMBOLGEN:  && resolves to &.
SYMBOLGEN:  Macro variable X resolves to 1
SYMBOLGEN:  Macro variable CUNM1 resolves to At&t                                                                                               
SYMBOLGEN:  Macro variable T resolves to           27


output:

in output &t also resolves in test to 27.
#3A - At          27

but i want to print the result as it is At&t


SAS Super FREQ
Posts: 8,868

Re: macro variable

Posted in reply to sunilreddy

Hi:

  I'm not sure what all your macro programs are doing, since generally, it is considered bad form to nest macro definitions the way you show. Also, since you have %MEND without the name of the macro definition that you are ending, it is hard to entirely follow the logic of what you are trying to do.

  However, in the simplest reduction of your logic to the essence (not sure you need the %QUOTE when you assign ORGNM a value), the code below -- with direct masking of the & in At&t, (or AT&T) the output seems to be correct. If you needed to check and adjust your CUSTOMER_DESC variable before your CALL SYMPUT, you can do that easily by using the SCAN function to break up the character variable and the CATT function to concatenate the %nrstr(&) inside the value. (or other methods, too -- it's just easier to do it in the DATA step where you have CALL SYMPUT and more direct to do it there, too.

cynthia

%let t = 27;

%let x = 1;

      

data _null_;

  customer_desc = 'AT%nrstr(&)T';

  call symput("CUNM" || strip(put(_n_,best.)), CUSTOMER_DESC);

run;

  

%put _user_;

       

%let orgnm=%quote(&&CUNM&x);

   

ods html file='c:\temp\protect_amp.html';

title " #3A - &orgnm.";

proc print data=sashelp.class(obs=2);

run;

ods html close;


ATT_in_TITLE_with_amp.png
Frequent Contributor
Posts: 115

Re: macro variable

Posted in reply to Cynthia_sas

Hi

Thanks for ur response.

I am able see the correct value if i hard coded text in %nrstr

all symput("CUNM" || strip(put(_n_,best.)), '%nrstr(at&T)');

but i want to pass the column name instead of hard coded, since i am generating macro variable from columns.

Frequent Contributor
Posts: 106

Re: macro variable

Posted in reply to sunilreddy

Instead of

%mrp_sdc(orgid=&&CUID&x, orgnm=%quote(&&CUNM&x));


try passing the variable name only. Somewhat like


%mrp_sdc(orgid=&&CUID&x, orgnm=CUNM&x);


and then resolve that in macro mrp_sdc like


title " #3A - %superq(&orgnm)" ;



Frequent Contributor
Posts: 115

Re: macro variable

Posted in reply to Robert_Bardos


Thanks a lot for ur help, its working

Ask a Question
Discussion stats
  • 4 replies
  • 370 views
  • 0 likes
  • 3 in conversation