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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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