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 |
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;
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;
Awesome. Thank you
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
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.