BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

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;

 

5 REPLIES 5
andreas_lds
Jade | Level 19

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.

Ronein
Onyx | Level 15
I need to work on the summary table that was created.......and add to him the desired categories
andreas_lds
Jade | Level 19

Then post the code you are using to create the summary table, if it is not proc summary.

PeterClemmensen
Tourmaline | Level 20

Untested:

 

proc summary data = Summarytbl nway completetypes;
   class Category / preloadfmt;
   var Value;
   output out = want(drop = _:) sum=;
   format Category $FFF.;
run;
andreas_lds
Jade | Level 19

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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 896 views
  • 0 likes
  • 3 in conversation