Source
A
B
C
We expect to see A B C as sources. But sometimes the source may not have all three values.
I would like to add missing source in this case C with sum 0 to final table.
Source TA sum
A diabetes 100
B diabetes 200
C diabetes 0
How are you generating the table? Code at least.
You might be able to use one of the procedures that supports PRELOADFMT to include all levels of a format for a variable in a table. That would require 1) a custom format for the variable with all of the levels and 2) the appropriate syntax for using PRELOADFMT.
Each procedure that allows use of the PRELOADFMT option has slight differences in syntax requirements so the following is only one way.
proc format library=work;
value $source
'A' = 'A'
'B' = 'B'
'C' = 'C'
;
run;
data example;
input source $ value;
datalines;
A 123
A 5
B 43
B 18
A 8
;
run;
proc tabulate data=example;
class source /preloadfmt ;
format source $source.;
var value;
table source,
value*sum
/ printmiss misstext='0'
;
run;
I don't understand this. Are A, B and C data sets or variables or?
Please be more specific
Make your own shell with all the values:
data shell;
sum=0;
do source='A', 'B', 'C';
output;
end;
run;
Then you can merge it with your original data:
data want;
merge shell have;
by source;
run;
data level; input source $; cards; A B C ; run; data example; input source $ value; datalines; A 123 A 5 B 43 B 18 A 8 ; run; proc summary data=example classdata=level nway; class source; var value; output out=want sum=; run;
Nearly 200 sessions are now available on demand in the Innovate Hub.
Watch Now →SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.