After Using proc freq to get count and percent. I was trying to put count and percent together. Here is the code :
proc freq data=tem1 ;
by treatmnt;
tables gender / out=gender0 noprint;
tables race / out=race0 noprint;
run;
proc freq data=tem1;
format percent commax10.1;
tables gender /out=gender1 noprint;
tables race /out=race1 noprint;
run;
data cate0;
set gender0 (in=a0)
gender1 (in=a1)
race0 (in=b0)
race1 (in=b1);
if a0 then do;
var=put(gender,gender.);
stat = put(count, 3.) || ' ('||put(trim(percent), 4.) ||'%'|| ') ' ;
end;
if a1 then do;
var=put(gender,gender.);
stat = put(count, 3.) || ' ('||put(trim(percent), 4.) ||'%'|| ') ' ;
end;
if b0 then do;
var=put(race, race.);
stat = put(count, 3.) || ' ('||put(trim(percent), 4.) ||'%'|| ') ' ;
end;
if b1 then do;
var=put(race,race.);
stat = put(count, 3.) || ' ('||put(trim(percent), 4.) ||'%'|| ') ' ;
end;
run;
Everything is working except the last value 50%.
The last column is what I want to use for next step. Is there anyone knows how to fix this.
Let 50.0% display
I think this simplification will do what you want:
stat = catx(' ', put(count, best.), put(percent/100, percent8.));
You could also change the first argument of catx if you'd like a different delimiter for the count and percent values.
I think this simplification will do what you want:
stat = catx(' ', put(count, best.), put(percent/100, percent8.));
You could also change the first argument of catx if you'd like a different delimiter for the count and percent values.
@collinelliot's suggestion should work, but you could also just change your 'TRIM' functions to be STRIP functions. e.g.:
data cate0;
set gender0 (in=a0)
gender1 (in=a1)
race0 (in=b0)
race1 (in=b1);
if a0 then a=a0;
if a1 then b=a1;
if b0 then c=b0;
if b1 then d=b1;
if a0 then do;
var=put(gender,gender.);
stat = put(count, 3.) || ' ('||put(strip(percent), 4.) ||'%'|| ') ' ;
end;
if a1 then do;
var=put(gender,gender.);
stat = put(count, 3.) || ' ('||put(strip(percent), 4.) ||'%'|| ') ' ;
end;
if b0 then do;
var=put(race, race.);
stat = put(count, 3.) || ' ('||put(strip(percent), 4.) ||'%'|| ') ' ;
end;
if b1 then do;
var=put(race,race.);
stat = put(count, 3.) || ' ('||put(strip(percent), 4.) ||'%'|| ') ' ;
end;
run;
HTH,
Art, CEO, AnalystFinder.com
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!
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.