BookmarkSubscribeRSS Feed
SASPhile
Quartz | Level 8

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

4 REPLIES 4
ballardw
Super User

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;
PeterClemmensen
Tourmaline | Level 20

I don't understand this. Are A, B and C data sets or variables or?

 

Please be more specific 

Astounding
PROC Star

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;
Ksharp
Super User
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;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 4 replies
  • 883 views
  • 1 like
  • 5 in conversation