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'm trying to resolve the macrovariable &PROFILE that has a text: "ne devra représenter plus de 20 %du profil de gestion".

I get the Warning message: WARNING: Apparent invocation of macro DU not resolved.

 

Do you know please how to avoid this message?

 

Thank you very much!

 

Best regards,

Marie

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Let's spell the issue out in more detail.   You want to use macro variables to generate a string constant in a call to some object method in a data step.  If you add double quotes around the value then the macro processor will try to evaluate the string value for possible macro references (% and/or & characters).  If you build the string with single quotes instead then the macro processor will ignore the value of the string constant so % and/or & will be left alone.

 

You are attempting to add the quotes after generating the macro variable.  You have no need for the unquoted string in your current program. So instead you could just add the quotes into the value of the macro variable when you create it.    Note there is no need to create the &ith macro variable &i times by processing observations 1 to &i.  Just use the one observation.

data _null_;
	set RESULTAT (firstobs=&i obs=&i);
	call symputx('PROFILE',quote(trim(PROFILE_NAME),"'"));
	call symputx('PROFILE_OBJECTIVES',quote(trim(PROFILE_OBJECTIVES),"'"));
run;

Then just use the macro variable, no need to add any quotes since they are already in the macro variable value.

 

 

obj.format_cell(data: &profile 
...
obj.format_cell(data: &PROFILE_OBJECTIVES
...

But best method is to just skip making the macro variables and use the actual dataset variables by reading in the observation you want in the data step that is making the object calls.

data _null_;
  set RESULTAT (firstobs=&i obs=&i);
  declare odsout obj();
  ...
  obj.format_cell(data: PROFILE_NAME 
  ...
  obj.format_cell(data: PROFILE_OBJECTIVES
  ...

 

View solution in original post

26 REPLIES 26
PeterClemmensen
Tourmaline | Level 20

Use a proper macro quoting function

 

data _null_;
   call symputx('profile', 'ne devra représenter plus de 20 %du profil de gestion');
run;

%put %superq(profile);
yabwon
Onyx | Level 15
haha! We have almost exactly the same answers 🙂 🙂

B-)
_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



SASdevAnneMarie
Barite | Level 11
I still have the same warning, my code is:

obj.row_start();
obj.format_cell(data:
"OBJECTIFS :" , overrides: "font_face=Calibri just=left font_weight=bold color=cx338AFF font_size=10pt width=2.6 cm");
obj.format_cell(data: %sysfunc(quote(%superq(PROFILE))) , overrides: "font_face=Calibri just=left color=black font_size=10pt ");
obj.row_end();
SASdevAnneMarie
Barite | Level 11
Thank you!
SASdevAnneMarie
Barite | Level 11
Hello Kurt,
Thank you for your answer!
I didn't understand , %sysfunc(quote(%superq(PROFILE_NAME))) worked in my code for another problem.
I can't use %sysfunc?
yabwon
Onyx | Level 15

try %superq()

data _null_;
  call symputX('PROFILE', 'ne devra représenter plus de 20 %du profil de gestion', "G");
run;

%put %superq(PROFILE);
_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



SASdevAnneMarie
Barite | Level 11
Thank you!

I still have the same warning, my code is:

obj.row_start();
obj.format_cell(data:
"OBJECTIFS :" , overrides: "font_face=Calibri just=left font_weight=bold color=cx338AFF font_size=10pt width=2.6 cm");
obj.format_cell(data: %sysfunc(quote(%superq(PROFILE))) , overrides: "font_face=Calibri just=left color=black font_size=10pt ");
obj.row_end();
yabwon
Onyx | Level 15

hmmm..

try with %qsysfunc()

data _null_;
  call symputX('PROFILE', 'ne devra représenter plus de 20 %du profil de gestion', "G");
run;

%put %qsysfunc(quote(%superq(PROFILE)));
_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



SASdevAnneMarie
Barite | Level 11
Hello, thank you!
%qsysfunc need a put, beacause I get the error:
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant,
a missing value, arrayname, (, +, -, INPUT, NOT, PUT, ^, _NEW_, ~.
I can't write a put, beacause I have an ods object code:


obj.row_start();
obj.format_cell(data:
"OBJECTIFS :" , overrides: "font_face=Calibri just=left font_weight=bold color=cx338AFF font_size=10pt width=2.6 cm");
obj.format_cell(data: %sysfunc(quote(%superq(PROFILE))) ,
overrides: "font_face=Calibri just=left color=black font_size=10pt ");
obj.row_end();
Tom
Super User Tom
Super User

Not sure what this statement is. Why does the first line end in a comma and not a semi-colon?  So assuming you want to run this statement:

obj.format_cell(data: %sysfunc(quote(%superq(PROFILE))) 
               ,overrides: "font_face=Calibri just=left color=black font_size=10pt ")
;

Does that statement allow you to use single quotes instead of double quotes?  Those will prevent the macro process from trying to evaluate the % and & triggers in the string.

obj.format_cell(data: %sysfunc(quote(%superq(PROFILE),%str(')))
               ,overrides: "font_face=Calibri just=left color=black font_size=10pt ")
;

Also does the syntax of that statement allow a variable or function instead of a string literal?

obj.format_cell(data: symget('PROFILE') 
               ,overrides: "font_face=Calibri just=left color=black font_size=10pt ")
;

 

SASdevAnneMarie
Barite | Level 11
Hello Tom,

Thank you for your suggestions.
Unfortunately it doesn't work. (
I added the code and xlsx file.

Best regards,
Marie
yabwon
Onyx | Level 15

and how about this:

 

data _null_;
  call symputX('PROFILE', 'ne devra représenter plus de 20 %du profil de gestion', "G");
run;

obj.row_start();
obj.format_cell(data:
"OBJECTIFS :" , overrides: "font_face=Calibri just=left font_weight=bold color=cx338AFF font_size=10pt width=2.6 cm");
obj.format_cell(data: %str(%')%superq(PROFILE)%str(%') ,
overrides: "font_face=Calibri just=left color=black font_size=10pt ");
obj.row_end();

for the format_cell data portion(according to the doc) can be enclosed in single quotes.

 

Bart

 

 

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



yabwon
Onyx | Level 15

or approach with `_temporary_variable_`?

data _null_;
  call symputX('PROFILE', 'ne devra représenter plus de 20 %du profil de gestion', "G");
run;


filename out "%sysfunc(pathname(WORK))";
ods html close;
ods html path=Out file="test.html";

data _null_;

  dcl odsout obj();
  obj.table_start();

  _temporary_variable_ = symget("PROFILE");
  drop _temporary_variable_;

  obj.row_start();
  obj.format_cell(data: "OBJECTIFS :", 
    overrides: "font_face=Calibri just=left font_weight=bold color=cx338AFF font_size=10pt width=2.6 cm");
  obj.format_cell(data: _temporary_variable_,
    overrides: "font_face=Calibri just=left color=black font_size=10pt ");
  obj.row_end();


  obj.table_end();
run;
ods html close;
ods html;

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 26 replies
  • 1816 views
  • 4 likes
  • 6 in conversation