BookmarkSubscribeRSS Feed
aha123
Obsidian | Level 7

I have a proc sql steps to produce a summary data based on the same table like this:

proc sql;

  create table combined as

  select 'type 1' as type, state, sum(paid_amt) as paid_amt

  from base

  where criteria1

  group by state

  union

  select 'type 2' as type, state, sum(paid_amt) as paid_amt

  from base

  where criteria2

  group by state

  .....

  select 'type 10' as type, state, sum(paid_amt) as paid_amt

  from base

  where criteria10

group by state

; run;

A record can belong to several types. base table needs to be run 10 times in this sql. I wonder if there is a trick to produce the summary data quicker.

5 REPLIES 5
Ksharp
Super User

I remember Keith has done it by using Multi-label format before.

Maybe Keith will appear again and code it for you . Smiley Happy

Ksharp

manojinpec
Obsidian | Level 7

what is criteria1 2 3...

Keith
Obsidian | Level 7

I'm obviously under pressure from @Ksharp here....

However, @manojinpec is right in that how the criteria is defined will determine how best to proceed.  If it is based on values of a single variable then multilabel format is a possibility.  If it is based on multiple conditions then I would suggest a datastep that creates variables Type1 - Type10 and stores a running total of paid_amt in each, thereby requiring only 1 pass of the data.

manojinpec
Obsidian | Level 7

Thanks Keith!! Could you please send me an example on how to use multilabel format.I haev never used it.

Keith
Obsidian | Level 7

Essentially it's a method that allows overlapping formats that can then be used in certain SAS procedures (SUMMARY, MEANS, TABULATE, REPORT).  If you google 'SAS multilabel format' then there are plenty of papers that describe this in more detail and provide some good examples.  The main things to note are :

  • add the option 'multilabel' inside PROC FORMAT.
  • add the option 'mlf' against the specific class variable inside the summary procedure.
  • include the format statement inside the summary procedure.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 1128 views
  • 0 likes
  • 4 in conversation