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

Stuck on simple question.

TrainCurrentLandingIn_LineIn_Tankage
Singles332
Doubles9814
Triples44
643
71
81

So I would like to combine all rows indicate 6,7,8 or more for column train into one row as"Quad+", and all the corresponding numbers combined as well.

Something like merge horizontally.

Thank you

Jack

This is desired result.

TrainCurrentLandingIn_LineIn_Tankage
Singles332
Doubles9814
Triples44
Quad+4311
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

One way is to recode TRAIN and then SUM the other variables.  Is that what you want?

data have ;

  input Train $ Current Landing In_Line In_Tankage ;

cards;

Singles 3 3 2 .

Doubles 9 8 1 4

Triples 4 4 . .

6 4 3 . .

7 . . . 1

8 . . 1 .

;;;;

data step1 ;

  set have ;

  if train not in ('Singles','Doubles','Triples') then train='Quad+' ;

run;

proc summary data=step1 nway ;

  class train ;

  var Current Landing In_Line In_Tankage;

  output out=want sum= ;

run;

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

One way is to recode TRAIN and then SUM the other variables.  Is that what you want?

data have ;

  input Train $ Current Landing In_Line In_Tankage ;

cards;

Singles 3 3 2 .

Doubles 9 8 1 4

Triples 4 4 . .

6 4 3 . .

7 . . . 1

8 . . 1 .

;;;;

data step1 ;

  set have ;

  if train not in ('Singles','Doubles','Triples') then train='Quad+' ;

run;

proc summary data=step1 nway ;

  class train ;

  var Current Landing In_Line In_Tankage;

  output out=want sum= ;

run;

JackZhang
Calcite | Level 5

Awesome. Thank you

Ksharp
Super User

Are these Train value unique ?

data have ;
  input Train $ Current Landing In_Line In_Tankage ;
cards;
Singles 3 3 2 .
Doubles 9 8 1 4
Triples 4 4 . .
6 4 3 . .
7 . . . 1
8 . . 1 .
;;;;
run;
proc sql;
create table want as
 select * from have where anyalpha(Train)
  union all
 select "Quad+" as Train,sum(Current) as Current,sum(Landing) as Landing,sum(In_Line) as In_Line,sum(In_Line) as In_Line
  from have 
   where anydigit(Train);
quit;

Xia Keshan

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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