Hello,
Lets say that I have created a summary table and the result is the summary table in the code below.
The task is to add categories that appear in proc format into the summary table.
What is the best and most useful way to do it?
Desired table is
A 10
B 30
C 0
D 0
E 20
F 0
G 80
H 0
Data Summarytbl;
Input Category $ Value;
Cards;
A 10
B 30
E 20
G 80
;
Run
proc format;
value $FFF
'A'='Reason_A'
'B'='Type B'
'C'='Unknown reason'
'D'='Reason D'
'E'='Issue E'
'F'='Task F'
'G'='Task G'
'H'='Task H'
;
Run;
Depends on how the summary table is created, proc summary e.g. has an option to create rows/columns for each value in a format. Please see the docs for details.
Then post the code you are using to create the summary table, if it is not proc summary.
Untested:
proc summary data = Summarytbl nway completetypes;
class Category / preloadfmt;
var Value;
output out = want(drop = _:) sum=;
format Category $FFF.;
run;
Another idea, applicable if you can't change the process creating the summary dataset:
data Summarytbl;
length Category $ 1 Value 8;
input Category $ Value;
cards;
A 10
B 30
E 20
G 80
;
run;
proc format;
value $FFF
'A'='Reason_A'
'B'='Type B'
'C'='Unknown reason'
'D'='Reason D'
'E'='Issue E'
'F'='Task F'
'G'='Task G'
'H'='Task H'
;
run;
proc format cntlout= FormatDef(keep= Start rename=(Start = Category));
select $FFF;
run;
data want;
merge FormatDef SummaryTbl;
by Category;
Value = coalesce(Value, 0);
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.