BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

Hello

In following code i am trying to change format of one way proc freq.

 

For example :

For Make=Hummer frequency=1 and  Relative Frequency should be 1/428=0.23%

But in the output we get 23%

 

What is the way to solve it?

I guess that something is wrong with pctfmt format

 

 

 

proc format; 
picture pctfmt low-high='000.00%';
run; 


ods path work.templat(update) sashelp.tmplmst(read); 
proc template; 
edit Base.Freq.OneWayList;
edit Percent;     
header="; Relative Frequency ;"; 
format=pctfmt.;   
justify= on;
end;
edit CumPercent; 
header = ";Cumulative;
Relative Frequency;"; 
format=pctfmt.;
justify= on;
end;   
end;
run;


proc freq data=sashelp.cars;
tables Make  / list;
run;
2 REPLIES 2
Rick_SAS
SAS Super FREQ

If it is helpful, SAS supports the PERCENTw.d format. 

Try PERCENT8.2.  If you have negative percentages, you can also use the PERCENTN8.2 format.

ballardw
Super User

@Ronein wrote:

Hello

In following code i am trying to change format of one way proc freq.

 

For example :

For Make=Hummer frequency=1 and  Relative Frequency should be 1/428=0.23%

But in the output we get 23%

 

What is the way to solve it?

I guess that something is wrong with pctfmt format

 

 

 

proc format; 
picture pctfmt low-high='000.00%';
run; 


ods path work.templat(update) sashelp.tmplmst(read); 
proc template; 
edit Base.Freq.OneWayList;
edit Percent;     
header="; Relative Frequency ;"; 
format=pctfmt.;   
justify= on;
end;
edit CumPercent; 
header = ";Cumulative;
Relative Frequency;"; 
format=pctfmt.;
justify= on;
end;   
end;
run;


proc freq data=sashelp.cars;
tables Make  / list;
run;

Digit selectors in Picture formats don't always work the way you think they will until you have worked with them a lot.

Typically the formats suggest by @Rick_SAS are likely what you want.

I also think this is the format you may have intended to basically duplicate that 8.2 (or similar range) would be:

 

proc format library=work; 
picture pctfmt low-high='009.99%';
run; 

The non-zero values in the string will force a character before the decimal, 0 if no actual value of 1 or greater in the data, and the non-zero after the decimal will always display 2 characters as appropriate (data will be truncated not rounded). Without any non-zero characters in the display string values that are less than 1 , such as your .23 don't really have a good alignment with the picture.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 2 replies
  • 812 views
  • 2 likes
  • 3 in conversation