Hi Everyone,
I have a table (example of current & what i'm looking for) and am not sure which data or proc statement is best to accomplish this and if I need to list out every column name that needs summed.
Current Table:
Date | ID | Weight | Height | Length | Miles |
11/10/2020 | A123D | 4.5 | 3 | 5 | 15 |
11/10/2020 | A123D | 5.5 | 5 | 7 | 10 |
11/10/2020 | B456E | 7.0 | 4 | 3 | 20 |
11/12/2020 | B456E | 6.0 | 6 | 8 | 12 |
11/12/2020 | A123D | 8.0 | 2 | 4 | 17 |
Look to sum by Date and ID, to hopefully get something like this:
Date | ID | Weight | Height | Length | Miles |
11/10/2020 | A123D | 10 | 8 | 12 | 25 |
11/10/2020 | B456E | 7.0 | 4 | 3 | 20 |
11/12/2020 | B456E | 6.0 | 6 | 8 | 12 |
11/12/2020 | A123D | 8.0 | 2 | 4 | 17 |
Try this
data have;
input Date :mmddyy10. ID $ Weight Height Length Miles;
format date mmddyy10.;
datalines;
11/10/2020 A123D 4.5 3 5 15
11/10/2020 A123D 5.5 5 7 10
11/10/2020 B456E 7.0 4 3 20
11/12/2020 B456E 6.0 6 8 12
11/12/2020 A123D 8.0 2 4 17
;
proc summary data = have nway;
class Date ID;
var Weight Height Length Miles;
output out = want(drop = _:) sum=;
run;
Result:
Date ID Weight Height Length Miles 11/10/2020 A123D 10 8 12 25 11/10/2020 B456E 7 4 3 20 11/12/2020 A123D 8 2 4 17 11/12/2020 B456E 6 6 8 12
Try this
data have;
input Date :mmddyy10. ID $ Weight Height Length Miles;
format date mmddyy10.;
datalines;
11/10/2020 A123D 4.5 3 5 15
11/10/2020 A123D 5.5 5 7 10
11/10/2020 B456E 7.0 4 3 20
11/12/2020 B456E 6.0 6 8 12
11/12/2020 A123D 8.0 2 4 17
;
proc summary data = have nway;
class Date ID;
var Weight Height Length Miles;
output out = want(drop = _:) sum=;
run;
Result:
Date ID Weight Height Length Miles 11/10/2020 A123D 10 8 12 25 11/10/2020 B456E 7 4 3 20 11/12/2020 A123D 8 2 4 17 11/12/2020 B456E 6 6 8 12
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!
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.