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: Call for Content

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!

Submit your idea!

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