BookmarkSubscribeRSS Feed
DaveShea
Lapis Lazuli | Level 10
I am using SAS Enterprise Guide 4.1 (4.1.0.471) and want to be able to use the Filter & Query task to summarise my data using an existing user-defined format to group my values.

As an example, my demo data looks like this:

Data Transactions;
Input Cust_No
Trans_Code
;
Datalines;
555 1
555 1
330 2
630 2
777 2
805 3
658 4
;
Run;

My demo format looks like this:

Proc Format Library=WORK;
Value Trans_Code 1,2 = "Purchases"
3,4,5,6,7,9 = "Cash Advances"
Other = "Unknown"
;
Run;

when hand-coding (ie writing SAS code myself) I can use either of the following techniques:

1) Use Proc Summary with a Format statement to group by the Trans_Code variable after being passed through the format Trans_Code.

Proc Summary Data=Transactions NWAY missing;
Class Trans_Code;
Format Trans_Code Trans_Code.;
Output Out=SummaryA(Drop=_TYPE_ Rename=(_FREQ_=NumberOfRows))
;
Run;

2) Use Proc SQL with a Put function to group Trans_Code values by the format, Trans_Code.

Proc SQL;
Create Table SummaryB As
Select Put(Trans_Code, Trans_Code.) As GroupTranscode,
Count(*) As NumberOfRows
From Transactions
Group By Calculated GroupTranscode
;
Quit;

However, I need to be able to do this same grouping from the Filter & Query task , ie without writing code. I realise that the Recode A Column feature of the Calculated Column option can produce the same results as I require, but having to hand-build the rules for re-coding a column each time is not practical. In my real data, there are many hundreds of discreet Trans_Code values and the SAS format that we have built reduces these down to about 50 groups.

Does anyone know how we can use the Filter & Query Task to do the above. The only way I can think of doing it is to build a Calculated Column with the Expression Builder and build an expression as:

Put(Trans_Code, Trans_Code.)

I wonder if I am missing something a bit more obvious that is buried in the Filter & Query Task somwhere.

Any thoughts, anyone ?

Many thanks,

Down-under-Dave
Wellington
New Zealand
2 REPLIES 2
RichardH_sas
SAS Employee
My suggestion would be exactly what you mention: create a new column using a PUT function and your user-defined format. IMO, I don't think you're missing anything simpler.
DerekAdams
Calcite | Level 5
Hi Dave


using your sample data to create Transactions and the trans_code format, I then used the filter query task and added the two columns and grouped by Cust_no.

I just changed the format of Cust_no to trans_code and came up with the same answer without using put statements.


PROC SQL;
CREATE TABLE WORK.Query_for_SUMMARYA AS SELECT SUMMARYA.Trans_Code FORMAT=TRANS_CODE.,
(SUM(SUMMARYA.NumberOfRows)) AS SUM_OF_NumberOfRows
FROM WORK.SUMMARYA AS SUMMARYA
GROUP BY SUMMARYA.Trans_Code;
QUIT;

Derek Message was edited by: Derek Adams

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 2 replies
  • 1553 views
  • 0 likes
  • 3 in conversation