BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

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
Meteorite | Level 14
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;

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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