Missed a percent value when use put()

Solved
Occasional Contributor
Posts: 5

Missed a percent value when use put()

[ Edited ]

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

Accepted Solutions
Solution
‎01-30-2017 05:02 PM
PROC Star
Posts: 311

Re: Missed a percent value when use put()

Posted in reply to tony7zxzx

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.

All Replies
Solution
‎01-30-2017 05:02 PM
PROC Star
Posts: 311

Re: Missed a percent value when use put()

Posted in reply to tony7zxzx

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.

Occasional Contributor
Posts: 5

Re: Missed a percent value when use put()

Posted in reply to collinelliot
Thank you!
Super User
Posts: 8,214

Re: Missed a percent value when use put()

Posted in reply to tony7zxzx

@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

Occasional Contributor
Posts: 5

Re: Missed a percent value when use put()

Thank you Sir!
☑ This topic is solved.

Need further help from the community? Please ask a new question.

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