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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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