BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
masonCL
Fluorite | Level 6
Dear SAS expert,
 
Thank you in advance for your help! I created a macro below to dynamically generate define statements that are being used in proc report. %bquote is being used here. However, proc report can't process it. You can see the error message below. Can you please help identify the reason? Thanks!
 
%macro ild_out;
%do i=2 %to &max_ild.;
%bquote(
define e%eval(&i.-1)_prog_yn / "Did event%eval(&i.-1) progress to a higher grade per Investigator (Y/N)" style(column)=[cellwidth=0.8in] display;
define e%eval(&i.-1)_prog_date / "If yes, date when event%eval(&i.-1) progressed to a higher grade (event&i.)" style(column)=[cellwidth=0.8in] display;
define e&i._grade / "Grade of event&i." style(column)=[cellwidth=0.8in] display;
define e&i._out / "Outcome of event&i." style(column)=[cellwidth=0.8in] display;
define e&i._action / "Dose action of event&i. for DXd ADC" style(column)=[cellwidth=0.8in] display;
)
%end;
%mend ild_out;
 
Using in proc report:
 
define e1_action / "Dose action of initial event" style(column)=[cellwidth=1.2in] display;
%ild_out
define e1_aft_adc_dur / "Duration" style(column)=[cellwidth=0.8in] display;
 
masonCL_0-1734535797947.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
yabwon
Onyx | Level 15

Call it like this:

%unquote(%ild_out)

Read this article to learn why:

https://stats.oarc.ucla.edu/wp-content/uploads/2016/02/bt185.pdf

 

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



View solution in original post

7 REPLIES 7
himself
Pyrite | Level 9

Hi, Instead of using %bquote, can use %nrstr to handle the special characters and ensure the macro variables are correctly interpreted.

 

%macro ild_out;
%do i=2 %to &max_ild.;
%nrstr(
define e%eval(&i.-1)_prog_yn / "Did event%eval(&i.-1) progress to a higher grade per Investigator (Y/N)" style(column)=[cellwidth=0.8in] display;
define e%eval(&i.-1)_prog_date / "If yes, date when event%eval(&i.-1) progressed to a higher grade (event&i.)" style(column)=[cellwidth=0.8in] display;
define e&i._grade / "Grade of event&i." style(column)=[cellwidth=0.8in] display;
define e&i._out / "Outcome of event&i." style(column)=[cellwidth=0.8in] display;
define e&i._action / "Dose action of event&i. for DXd ADC" style(column)=[cellwidth=0.8in] display;
)
%end;
%mend ild_out;

Hope this helps

masonCL
Fluorite | Level 6

Thanks a lot, himself! It didn't process and reported the message below. All the macro variables are masked in the define blocks.

 

masonCL_0-1734537264535.png

 

yabwon
Onyx | Level 15

Call it like this:

%unquote(%ild_out)

Read this article to learn why:

https://stats.oarc.ucla.edu/wp-content/uploads/2016/02/bt185.pdf

 

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



masonCL
Fluorite | Level 6
Thanks a lot, Yabwon! Your solution works perfectly. I'll read the article you provided. 
Tom
Super User Tom
Super User

Why do you want to use %BQUOTE()?  It does not seem to serve any purpose.

%macro ild_out;
%local next previous style;
%let style=style(column)=[cellwidth=0.8in] display;
%do next=2 %to &max_ild.;
  %let previous=%eval(&next-1);
define e&previous._prog_yn / "Did event&previous. progress to a higher grade per Investigator (Y/N)" &style.;
define e&previous._prog_date / "If yes, date when event&previous. progressed to a higher grade (event&i.)" &style.;
define e&next._grade / "Grade of event&next." &style.;
define e&next._out / "Outcome of event&next." &style.;
define e&next._action / "Dose action of event&next. for DXd ADC" &style.;
%end;
%mend ild_out;

Also where does the value for the "magic" macro variable MAX_ILD come from? It is not a parameter that the macro accepts. Nor is it another LOCAL macro variable that macro created.

 

masonCL
Fluorite | Level 6

Thank you so much, Tom! &maxild is the maximum number of events that was defined in other data step. Your solution also works perfectly. I wish I could mark it as the second solution. Much appreciate it.

masonCL
Fluorite | Level 6
You are right! %bquote doesn't serve any purpose here. That's the key point. Thank you again for your help!

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 7 replies
  • 1218 views
  • 5 likes
  • 4 in conversation