| 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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.