BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

Hello

I am using proc template to edit output of two way freq table.

The calculation of Relative Frequency is not accurate and I want to ask why and how can we solve it?

For example: 

For  Make=Acura and Type=Sedan frequency=5 so Relative Frequency should be 5/428=1.17%

But in the output you can see that we get 1.16%

Why there is a difference???

 

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 * Type / list;
run;
5 REPLIES 5
ChrisNZ
Tourmaline | Level 20

Nothing to do with proc template and everything to do with your picture format. 

Consider:

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

data _null_;
  X=1.1688; putlog X= pctfmt.;
run;

X=1.16%

 

Ronein
Onyx | Level 15

Thank you.

Can you help with the full code?

I didn't  understand how to apply it

 

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

proc freq data=sashelp.cars;
tables Make * Type / list;
format ???????? pctfmt.;
run;
ChrisNZ
Tourmaline | Level 20

You are editing the one-way list template but are outputting a 2-way list. 

 

Ronein
Onyx | Level 15

Do you have two way template?

ChrisNZ
Tourmaline | Level 20

Sorry I am not a friend of proc template's. 🙂

Why don't you use proc tabulate?

proc format; 
  picture pctfmt low-high='000,009.00%' (multiplier=100);
run; 

proc tabulate data=SASHELP.CARS;
  class MAKE TYPE ;
  table MAKE all, (TYPE all)*pctn=' '*f=pctfmt10.2;
run;

  Type All
Hybrid SUV Sedan Sports Truck Wagon
Make   0.23% 1.16% 0.23%     1.63%
Acura
Audi     3.03% 0.93%   0.46% 4.43%
BMW   0.46% 3.03% 0.93%   0.23% 4.67%
Buick   0.46% 1.63%       2.10%
Cadillac   0.46% 0.93% 0.23% 0.23%   1.86%
Chevrolet   0.93% 3.50% 0.46% 1.16% 0.23% 6.30%
Chrysler     3.03% 0.23%   0.23% 3.50%
Dodge   0.23% 1.86% 0.23% 0.70%   3.03%
Ford   0.93% 2.57% 0.70% 0.70% 0.46% 5.37%
GMC   0.70% 0.23%   0.93%   1.86%
Honda 0.46% 0.70% 2.57% 0.23%     3.97%
Hummer   0.23%         0.23%
Hyundai   0.23% 2.33% 0.23%     2.80%
Infiniti     1.40%     0.46% 1.86%
Isuzu   0.46%         0.46%
Jaguar     1.86% 0.93%     2.80%
Jeep   0.70%         0.70%
Kia   0.23% 2.10%     0.23% 2.57%
Land Rover   0.70%         0.70%
Lexus   0.70% 1.40% 0.23%   0.23% 2.57%
Lincoln   0.46% 1.63%       2.10%
MINI     0.46%       0.46%
Mazda   0.23% 0.93% 0.93% 0.46%   2.57%
Mercedes-Benz   0.46% 3.73% 1.16%   0.70% 6.07%
Mercury   0.23% 1.63%     0.23% 2.10%
Mitsubishi   0.70% 1.40% 0.70%   0.23% 3.03%
Nissan   0.70% 2.10% 0.46% 0.46% 0.23% 3.97%
Oldsmobile     0.70%       0.70%
Pontiac   0.23% 1.86% 0.23%   0.23% 2.57%
Porsche   0.23%   1.40%     1.63%
Saab     1.40%     0.23% 1.63%
Saturn   0.23% 1.40%     0.23% 1.86%
Scion     0.23%     0.23% 0.46%
Subaru     1.40% 0.46% 0.23% 0.46% 2.57%
Suzuki   0.46% 1.16%     0.23% 1.86%
Toyota 0.23% 1.16% 3.73% 0.46% 0.70% 0.23% 6.54%
Volkswagen   0.23% 2.57%     0.70% 3.50%
Volvo   0.23% 2.10%     0.46% 2.80%
All 0.70% 14.01% 61.21% 11.44% 5.60% 7.00% 100.00%

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

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
  • 5 replies
  • 1895 views
  • 0 likes
  • 2 in conversation