BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Rhino84
Fluorite | Level 6

I need help in designing a query o/p.

tHE INPUT DATA SET IS LIKE THIS:

Each ID is spread into JAN to Dec with different amounts. I want to display a common ID with Date field as JAn20 till DEc 20 and AMT field should hold total amount for all JAN 20 values for each ID.

ID DATEAMT
XXXJAN2012
XXXJAN2013
XXXFEB207
XXXFEB208
XXXMAR2025
...
...
...
...
VVVJAN207
VVVJAN2114
VVVJAN2225

 

 

  

 

The output table should look like this.

 

ID DATEAMT
XXXJAN2023
XXXFEB2015
XXXMAR2025
ZZZJAN2015
ZZZFEB2063
ZZZMAR2047
AAAJAN2045
AAAFEB206
AAAMAR206
VVVJAN207
VVVFEB2014
VVVMAR2025
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

PROC MEANS

 

proc means data=have NWAY SUM;
class ID DATE;
var AMT;
output out=want sum(AMT)=AMT;
run;

proc print data=want;
run;

@Rhino84 wrote:

I need help in designing a query o/p.

tHE INPUT DATA SET IS LIKE THIS:

Each ID is spread into JAN to Dec with different amounts. I want to display a common ID with Date field as JAn20 till DEc 20 and AMT field should hold total amount for all JAN 20 values for each ID.

ID  DATE AMT
XXX JAN20 12
XXX JAN20 13
XXX FEB20 7
XXX FEB20 8
XXX MAR20 25
. . .
. . .
. . .
. . .
VVV JAN20 7
VVV JAN21 14
VVV JAN22 25

 

 

   

 

The output table should look like this.

 

ID  DATE AMT
XXX JAN20 23
XXX FEB20 15
XXX MAR20 25
ZZZ JAN20 15
ZZZ FEB20 63
ZZZ MAR20 47
AAA JAN20 45
AAA FEB20 6
AAA MAR20 6
VVV JAN20 7
VVV FEB20 14
VVV MAR20 25

 

View solution in original post

2 REPLIES 2
Reeza
Super User

PROC MEANS

 

proc means data=have NWAY SUM;
class ID DATE;
var AMT;
output out=want sum(AMT)=AMT;
run;

proc print data=want;
run;

@Rhino84 wrote:

I need help in designing a query o/p.

tHE INPUT DATA SET IS LIKE THIS:

Each ID is spread into JAN to Dec with different amounts. I want to display a common ID with Date field as JAn20 till DEc 20 and AMT field should hold total amount for all JAN 20 values for each ID.

ID  DATE AMT
XXX JAN20 12
XXX JAN20 13
XXX FEB20 7
XXX FEB20 8
XXX MAR20 25
. . .
. . .
. . .
. . .
VVV JAN20 7
VVV JAN21 14
VVV JAN22 25

 

 

   

 

The output table should look like this.

 

ID  DATE AMT
XXX JAN20 23
XXX FEB20 15
XXX MAR20 25
ZZZ JAN20 15
ZZZ FEB20 63
ZZZ MAR20 47
AAA JAN20 45
AAA FEB20 6
AAA MAR20 6
VVV JAN20 7
VVV FEB20 14
VVV MAR20 25

 

Rhino84
Fluorite | Level 6
Thank you so much REEZA !!

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