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

Hi there!

 

I'm new to SAS programming, and trying to write the statement "In X patients of study, y% are not having data" in my ods statement, but the values are not getting calculated as expected.

 

Requirement:

I've two macro variables and I'd like to write a string to ods, in that string add a percentage calculated from the two macro variables.

%let x = 20;

%total = 150;

ods rtf text = "~S={outputwidth=100% just=c font=('Times New Roman',12pt)} { *In &x patients of study. (round(&x./&total. * 100,.02)%) are not having data}";

 

Question:

Seems like round function only works in data step, but here it's not working.

How can I calculate the percentage on the fly and include in the ods text.

 

Thanks a lot in advance!

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

It seems it's now time to learn how to use the %sysfunc function.

View solution in original post

3 REPLIES 3
ChrisNZ
Tourmaline | Level 20

It seems it's now time to learn how to use the %sysfunc function.

Kurt_Bremser
Super User

To use a data step function like that, you need to wrap it in %sysfunc, and for calculations, you need either %eval (integer) or %sysevalf (floating point).

Since that would blow up the code and make it less readable, I prefer a data _null_ step:

data _null_;
call symputx('rate',put(&x./&total.,percent7.2));
run;
ods rtf text = "~S={outputwidth=100% just=c font=('Times New Roman',12pt)} { *In &total. patients of study, &rate. are not having data}"

 

chandanar
Calcite | Level 5

Thank you so much @Kurt_Bremser , that worked!

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 838 views
  • 1 like
  • 3 in conversation