SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SAS49
Obsidian | Level 7
ID1ID2Length
A_001A_005450
A_001A_005600
A_001A_005700
A_001A_006350
A_001A_006800
A_005A_006900
A_005A_006750

 

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: 

 

ID1ID2Length
A_001A_0051750
A_001A_0061150
A_005A_0061650

 

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. 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

I would let PROC SUMMARY have all the fun.

 

proc summary data=have nway;
    class id1 id2;
    var length;
    output out=want sum=;
run;
--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

I would let PROC SUMMARY have all the fun.

 

proc summary data=have nway;
    class id1 id2;
    var length;
    output out=want sum=;
run;
--
Paige Miller
tarheel13
Rhodochrosite | Level 12
proc sql;
create table want as
select id1, id2, sum(length) as length
from have 
group by id1, id2;
quit;

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

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
  • 2 replies
  • 2739 views
  • 0 likes
  • 3 in conversation