BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SASdevAnneMarie
Barite | Level 11

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! 

1 ACCEPTED SOLUTION

Accepted Solutions
RichardDeVen
Barite | Level 11

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;

View solution in original post

12 REPLIES 12
Kurt_Bremser
Super User

@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.;

 

SASdevAnneMarie
Barite | Level 11
Hello,

I need the additional quotation mark, beacause,, I use "&PRODUIT." in ods code
It is just a short example )

Kurt_Bremser
Super User

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.

RichardDeVen
Barite | Level 11

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
Barite | Level 11
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!
Tom
Super User Tom
Super User

@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(%')));
SASdevAnneMarie
Barite | Level 11

Thank you Richard! 

I'm trying to do that for "real" code but I still have the same error:

MarieT_0-1594219970326.png

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.

Tom
Super User Tom
Super User

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.

SASdevAnneMarie
Barite | Level 11
Thank you! That works!
SASdevAnneMarie
Barite | Level 11
Which is the best way in your opinion to get the number of observations please in this case?
Thank you for your help!
Kurt_Bremser
Super User
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.

SASdevAnneMarie
Barite | Level 11
Thank you very much!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 12 replies
  • 2763 views
  • 2 likes
  • 4 in conversation