What do I need to add here so that this line works?
put '%allProgForAcadDisplayInter(%bquote(' SMRPRLE_PROGRAM +(-1), SMRPRLE_PROGRAM_DESC +(-1) '))';
%global curProgram curProgramDesc; %macro allProgForAcadDisplayInter(curProgram, curProgramDesc); %let curProgram = &curProgram; %put curProgram &curProgram; %put curProgramDesc &curProgramDesc; %mend; %macro DisplayDemo(); proc sql; create table AllProgramList ( SMRPRLE_PROGRAM varchar(100), SMRPRLE_PROGRAM_DESC varchar(100) ); insert into AllProgramList(SMRPRLE_PROGRAM, SMRPRLE_PROGRAM_DESC) values ("One", "Apple"); insert into AllProgramList(SMRPRLE_PROGRAM, SMRPRLE_PROGRAM_DESC) values ("Two", "Orange"); quit; filename code temp; data _null_; set AllProgramList; file code; put '%allProgForAcadDisplayInter(%bquote(' SMRPRLE_PROGRAM +(-1) '))'; put '%allProgForAcadDisplayInter(%bquote(' SMRPRLE_PROGRAM +(-1), SMRPRLE_PROGRAM_DESC +(-1) '))'; /*how can I make this line work*/ run; %include code / source2; %mend; %DisplayDemo();
Found it
put '%allProgForAcadDisplayInter(%bquote(' SMRPRLE_PROGRAM +(-1) '), %bquote(' SMRPRLE_PROGRAM_DESC +(-1) '))';
Found it
put '%allProgForAcadDisplayInter(%bquote(' SMRPRLE_PROGRAM +(-1) '), %bquote(' SMRPRLE_PROGRAM_DESC +(-1) '))';
If you find that you frequently need to macro quote the arguments to your macro you might find it easier to pass the values with actual quotes. Especially if you are passing the values with SAS code where you could use the QUOTE() function to add the quotes.
Just make your macro smart enough to remove the quotes. Assuming you actually need to remove them, since most values that would require elaborate quoting to be used a macro call are probably going to be used by the macro to generate SAS code where you would just have to add the quotes back anyway.
Here is an example where the macro can pull off the quotes (if there) and then add them back when needed.
%macro mymacro(parm1,parm2);
%local q1 q2 ;
%let parm1=%qsysfunc(dequote(&parm1));
%let parm2=%qsysfunc(dequote(&parm2));
%let q1=%sysfunc(quote(&parm1,%str(%')));
%let q2=%sysfunc(quote(&parm2,%str(%')));
%put &=parm1 &=parm2;
%put &=q1 &=q2;
data _null_;
put 'parm1=' &q1 ;
put 'parm2=' &q2 ;
put "Both = &parm1 &parm2" ;
run;
%mend mymacro;
Example calls:
73 options mprint; 74 %mymacro(parm1=Hi there,parm2='Has a,comma'); PARM1=Hi there PARM2=Has a,comma Q1='Hi there' Q2='Has a,comma' MPRINT(MYMACRO): data _null_; MPRINT(MYMACRO): put 'parm1=' 'Hi there' ; MPRINT(MYMACRO): put 'parm2=' 'Has a,comma' ; MPRINT(MYMACRO): put "Both = Hi there Has a,comma" ; MPRINT(MYMACRO): run; parm1=Hi there parm2=Has a,comma Both = Hi there Has a,comma NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds 75 %mymacro(parm1='Hi there',parm2=%bquote(Has a,comma)); PARM1=Hi there PARM2=Has a,comma Q1='Hi there' Q2='Has a,comma' MPRINT(MYMACRO): data _null_; MPRINT(MYMACRO): put 'parm1=' 'Hi there' ; MPRINT(MYMACRO): put 'parm2=' 'Has a,comma' ; MPRINT(MYMACRO): put "Both = Hi there Has a,comma" ; MPRINT(MYMACRO): run; parm1=Hi there parm2=Has a,comma Both = Hi there Has a,comma NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds 76 %mymacro(parm1="Hi there",parm2=%bquote(Hasn't a comma)); PARM1=Hi there PARM2=Hasn't a comma Q1='Hi there' Q2='Hasn''t a comma' MPRINT(MYMACRO): data _null_; MPRINT(MYMACRO): put 'parm1=' 'Hi there' ; MPRINT(MYMACRO): put 'parm2=' 'Hasn''t a comma' ; MPRINT(MYMACRO): put "Both = Hi there Hasn't a comma" ; MPRINT(MYMACRO): run; parm1=Hi there parm2=Hasn't a comma Both = Hi there Hasn't a comma NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds
That depends on what it is supposed to do. My guessing skills lead me to believe that a change is required in the middle where this appears:
+(-1),
I imagine you want the comma to become part of the CODE file, and thus would need:
+(-1) ","
Ah, even better that you found the solution yourself!
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.