The SAS Output Delivery System and reporting techniques

Solved
Occasional Contributor
Posts: 9

Stuck on simple question.

 Train Current Landing In_Line In_Tankage Singles 3 3 2 Doubles 9 8 1 4 Triples 4 4 6 4 3 7 1 8 1

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.

 Train Current Landing In_Line In_Tankage Singles 3 3 2 Doubles 9 8 1 4 Triples 4 4 Quad+ 4 3 1 1

Accepted Solutions
Solution
‎03-17-2015 05:08 PM
Super User
Posts: 8,115

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;

All Replies
Solution
‎03-17-2015 05:08 PM
Super User
Posts: 8,115

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;

Occasional Contributor
Posts: 9

Awesome. Thank you

Super User
Posts: 10,784

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

🔒 This topic is solved and locked.