BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
tony7zxzx
Calcite | Level 5

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

 

Screen Shot 2017-01-30 at 4.04.52 PM.png

The last column is what I want to use for next step. Is there anyone knows how to fix this.

Let 50.0% display

1 ACCEPTED SOLUTION

Accepted Solutions
collinelliot
Barite | Level 11

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.

View solution in original post

4 REPLIES 4
collinelliot
Barite | Level 11

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.

tony7zxzx
Calcite | Level 5
Thank you!
art297
Opal | Level 21

@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

 

tony7zxzx
Calcite | Level 5
Thank you Sir!

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

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
  • 4 replies
  • 1128 views
  • 0 likes
  • 3 in conversation