The SAS Output Delivery System and reporting techniques

Help please

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 9
Accepted Solution

Help please

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

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

Re: Help please

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


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

Re: Help please

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

Re: Help please

Awesome. Thank you

Super User
Posts: 9,687

Re: Help please

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.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 443 views
  • 0 likes
  • 3 in conversation