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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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