One way is to create a table of the possible graphvar values and use a left join with the output table from proc freq. You loose the cumulative count and frequency, but hopefully that is not important.
data graphvar_tbl;
input graphvar cost_range $20.;
datalines;
1 $27,350 and Below
2 $27,350-$29,350
3 $29,350-$31,350
4 $31,350-$33,350
5 $33,350-$35,350
6 $35,350-$37,350
7 Above $37,350
;
data test;
srvc = 0;
graphvar = 1; do i=1 to 6; output; end;
graphvar = 3; do i=1 to 21; output; end;
graphvar = 4; do i=1 to 83; output; end;
graphvar = 5; do i=1 to 16; output; end;
graphvar = 6; do i=1 to 2; output; end;
graphvar = 7; do i=1 to 4; output; end;
run;
PROC FREQ DATA=TEST NLEVELS;
BY srvc;
TABLES GRAPHVAR/LIST MISSING out=test_freq;
RUN;
proc contents varnum data=test_freq;
/*
# Variable Type Len Label
1 srvc Num 8
2 graphvar Num 8
3 COUNT Num 8 Frequency Count
4 PERCENT Num 8 Percent of Total Frequency
*/
proc sql;
create table test_results as
select coalesce(b.srvc,0) as srvc,
a.graphvar, a.cost_range,
coalesce(b.count,0) as count,
coalesce(b.percent,0) format 5.2 as percent
from graphvar_tbl A
left join test_freq B on b.graphvar = a.graphvar
;
select * from test_results;
/*
srvc graphvar cost_range count percent
-----------------------------------------------------------
0 1 $27,350 and Below 6 4.55
0 2 $27,350-$29,350 0 0.00
0 3 $29,350-$31,350 21 15.91
0 4 $31,350-$33,350 83 62.88
0 5 $33,350-$35,350 16 12.12
0 6 $35,350-$37,350 2 1.52
0 7 Above $37,350 4 3.03
*/
... View more