How can I concatenate the count and percent into this form: xxx(xxx.x%) and round the percent to one decimal?
example data:
data CP;
input Treatment$ SEX$ COUNT PERCENT;
H1 Male 2 22.22%
H1 Female 7 77.77%
H2 Male 4 36.36%
H2 Female 7 63.63%
;
run;
So if you have actual percentages (so 0.2222 instead of 22.22 )
data CP;
input Treatment $ SEX $ COUNT PERCENT :percent.;
cards;
H1 Male 2 22.22%
H1 Female 7 77.77%
H2 Male 4 36.36%
H2 Female 7 63.63%
;
You could use the fact that the PERCENT format adds () around negative values to make it easier.
data want;
set cp;
length string $20;
string=put(count,comma12.)||' '|| put(-percent,percent7.1);
run;
Obs Treatment SEX COUNT PERCENT string 1 H1 Male 2 0.2222 2 (22.2%) 2 H1 Female 7 0.7777 7 (77.8%) 3 H2 Male 4 0.3636 4 (36.4%) 4 H2 Female 7 0.6363 7 (63.6%)
So if you have actual percentages (so 0.2222 instead of 22.22 )
data CP;
input Treatment $ SEX $ COUNT PERCENT :percent.;
cards;
H1 Male 2 22.22%
H1 Female 7 77.77%
H2 Male 4 36.36%
H2 Female 7 63.63%
;
You could use the fact that the PERCENT format adds () around negative values to make it easier.
data want;
set cp;
length string $20;
string=put(count,comma12.)||' '|| put(-percent,percent7.1);
run;
Obs Treatment SEX COUNT PERCENT string 1 H1 Male 2 0.2222 2 (22.2%) 2 H1 Female 7 0.7777 7 (77.8%) 3 H2 Male 4 0.3636 4 (36.4%) 4 H2 Female 7 0.6363 7 (63.6%)
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.