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 |
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
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
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.