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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 814 views
  • 0 likes
  • 3 in conversation