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

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
1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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 

 

 

View solution in original post

1 REPLY 1
PeterClemmensen
Tourmaline | Level 20

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 

 

 

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
  • 931 views
  • 4 likes
  • 2 in conversation