Hello,
I have a quoted macro variable PRODUIT (see the code), with a quotation mark inside.
Do you know how to resolve correctly this macro variable?
Thank you!
data test;
input X1 $5.;
cards;
"cd3"
"cd4"
;
run;
%macro my_var;
DATA _null_;
SET test END=eof;
IF eof THEN
DO;
CALL SYMPUT('nb',put(_N_,8.));
END;
run;
%do i=1 %to &nb.;
data _NULL_;
set test(obs=&i);
CALL SYMPUTX('PRODUIT',X1);
run;
%put "&PRODUIT.";
%end;
%mend;
%my_var;
Thank you very much!
Try using DEQUOTE.
CALL SYMPUTX('PRODUIT', DEQUOTE(X1) );
The rest of your code is a real hodgepodge and indicates maybe you need to learn a bit more before jumping into macro.
For example:
This is the WRONG WAY to get the number of observations in a data set
DATA _null_; SET test END=eof; IF eof THEN DO; CALL SYMPUT('nb',put(_N_,8.)); END; run;
Without knowing the planned use of the macro I speculate this is too much overwriting of the target macro symbol PRODUIT
%do i=1 %to &nb.; data _NULL_; set test(obs=&i); * CALL SYMPUTX('PRODUIT',X1);
CALL SYMPUTX('PRODUIT',DEQUOTE(X1)); %* Regardless, this is where DEQUOTE might go; run; %put "&PRODUIT."; %end;
@SASdevAnneMarie wrote:
Hello,
I have a quoted macro variable PRODUIT (see the code), with a quotation mark inside.
Do you know how to resolve correctly this macro variable?
Thank you!
data test;
input X1 $5.;
cards;
"cd3"
"cd4"
;
run;%macro my_var;
DATA _null_;
SET test END=eof;IF eof THEN
DO;
CALL SYMPUT('nb',put(_N_,8.));
END;
run;%do i=1 %to &nb.;
data _NULL_;
set test(obs=&i);
CALL SYMPUTX('PRODUIT',X1);
run;
%put "&PRODUIT.";
%end;%mend;
%my_var;
Thank you very much!
Don't use the additional double quotes in the %PUT:
%put &PRODUIT.;
Having quotes in macro variables is always a BAD IDEA.
Having double quotes in macro variables is a DOUBLE BAD IDEA, as you have experienced.
Please show us how you want to use that macro variable in your ODS code.
Try using DEQUOTE.
CALL SYMPUTX('PRODUIT', DEQUOTE(X1) );
The rest of your code is a real hodgepodge and indicates maybe you need to learn a bit more before jumping into macro.
For example:
This is the WRONG WAY to get the number of observations in a data set
DATA _null_; SET test END=eof; IF eof THEN DO; CALL SYMPUT('nb',put(_N_,8.)); END; run;
Without knowing the planned use of the macro I speculate this is too much overwriting of the target macro symbol PRODUIT
%do i=1 %to &nb.; data _NULL_; set test(obs=&i); * CALL SYMPUTX('PRODUIT',X1);
CALL SYMPUTX('PRODUIT',DEQUOTE(X1)); %* Regardless, this is where DEQUOTE might go; run; %put "&PRODUIT."; %end;
@SASdevAnneMarie wrote:
Hello Richard,
It is just a short example, for understanding the probleme. It is NOT a real code, I need the quotation mark beacause I code the ods object report.
Thank you!
If the macro variable value COULD have quote character and you want to add quotes around it do not use:
%put "&mvar";
Instead use the QUOTE() function.
%put %sysfunc(quote(&mvar));
Note that the QUOTE() function now supports a second parameter to tell it what quote character to use on the outside. So if the macro variable value could contain macro triggers like & or % then use single quotes on the outside to prevent the macro processor from trying to evaluate them as macro variable or macro function references.
%put %sysfunc(quote(&mvar,%str(%')));
Thank you Richard!
I'm trying to do that for "real" code but I still have the same error:
NOTE: Line generated by the macro variable "PROFILE_NAME".
919 "Profilée Non "Sécuritaire"
____________________________________________________
49 388
202
ERROR: DATA STEP Component Object failure. Aborted during the COMPILATION phase.
NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS release. Inserting white space
between a quoted string and the succeeding identifier is recommended.
ERROR 388-185: Expecting an arithmetic operator.
ERROR 202-322: The option or parameter is not recognized and will be ignored.
So if the macro variable does NOT have macro quoting already (which I thought you said it did in your original post) then you need to add that before passing the value to the QUOTE() function.
%sysfunc(quote(%superq(MVAR)))
Note that %SUPERQ() wants the NAME of the macro variable, not its value.
data _null_;
call symputx('nobs',nobs);
set test nobs=nobs;
run;
You need to do the call symputx before an eventual end-of-file (when there are zero observations) causes the immediate termination of the data step.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.