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;
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%
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;
You are editing the one-way list template but are outputting a 2-way list.
Do you have two way template?
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% |
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.