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%)
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.