ID1 | ID2 | Length |
A_001 | A_005 | 450 |
A_001 | A_005 | 600 |
A_001 | A_005 | 700 |
A_001 | A_006 | 350 |
A_001 | A_006 | 800 |
A_005 | A_006 | 900 |
A_005 | A_006 | 750 |
Hi all, I am very new to SAS. I have a data table of comparisons between 2 different IDs (found in columns 1 and 2), and the lengths shared between them. There are multiple lengths listed for these different pairs. I want the sum of lengths for each of the matching pairs and to output that as a separate data table. See the example below:
ID1 | ID2 | Length |
A_001 | A_005 | 1750 |
A_001 | A_006 | 1150 |
A_005 | A_006 | 1650 |
How would I accomplish this in SAS? I honestly have no idea where even to start. I appreciate any advice! I am working in SAS 9.4.
I would let PROC SUMMARY have all the fun.
proc summary data=have nway;
class id1 id2;
var length;
output out=want sum=;
run;
I would let PROC SUMMARY have all the fun.
proc summary data=have nway;
class id1 id2;
var length;
output out=want sum=;
run;
proc sql;
create table want as
select id1, id2, sum(length) as length
from have
group by id1, id2;
quit;
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.