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!

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
  • 3 replies
  • 1200 views
  • 1 like
  • 3 in conversation