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!
It seems it's now time to learn how to use the %sysfunc function.
It seems it's now time to learn how to use the %sysfunc function.
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}"
Thank you so much @Kurt_Bremser , that worked!
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!
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.