BookmarkSubscribeRSS Feed
deleted_user
Not applicable
hello all,

I have very complex query to make (for me at least!)

I have (example):
A B C
05-06-2009 1 10
05-06-2009 1 20
05-06-2009 2 20
06-06-2009 1 40
06-06-2009 1 40
06-06-2009 2 50
06-06-2009 2 50
06-06-2009 2 30
06-06-2009 2 20
07-06-2009 1 20
07-06-2009 2 10
07-06-2009 3 30
08-06-2009 3 30

The goal is to create a D and E column with range of amounts and accumulated total per day (A) for each (B) custumer

accumulated total per day (A) for each (B) custumer has to be > 10

ranges:
10>= accumulated total per day (A) for each (B) custumer < 20
20>= accumulated total per day (A) for each (B) custumer < 30
and so on!

A B D E
05-06-2009 1 20 20=<30
06-06-2009 1 40 x=>40
07-06-2009 1 20 20=<30
05-06-2009 2 20 20=<30
06-06-2009 2 150 x=>40
07-06-2009 2 10 10=<20
07-06-2009 3 30 30=<40
08-06-2009 3 30 30=<40



It has to be done in proc sql :s
any ideas?! I'm sorry that I can't explain better but I don't have access for now to SAS

thanks in advance!
1 REPLY 1
DanielSantos
Barite | Level 11
Hmmm... You just have about a millions ways to do this with SAS.

Anyway, It's just a simple grouping case, I wouldn't call it a complex problem.

But for the resulting table:

A B D E
05-06-2009 1 20 20=<30
06-06-2009 1 40 x=>40
07-06-2009 1 20 20=<30
05-06-2009 2 20 20=<30
06-06-2009 2 150 x=>40
07-06-2009 2 10 10=<20
07-06-2009 3 30 30=<40
08-06-2009 3 30 30=<40

I understand that E would be the range for the group (each day), and what about D?
And also which B should be chosen for each group?

Just for A and E, try this:

proc sql noprint;
create table RESULT as
select A, min(C) as MINC, max(C) as MAXC from LIB.DATA;
quit;

This will give you for each day, and the minimum and maximum values of C (range).

Cheers from Portugal.

Daniel Santos @ www.cgd.pt.

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
  • 1 reply
  • 627 views
  • 0 likes
  • 2 in conversation