如何将数据添加到不同组的 SAS table 中?
How can I add data into a SAS table of different groups?
主键是car、model和date,我要用之前的数据填空字段,但是它的主键是car和model。
示例:
Row Car Model Date Sec Door Colour
1 Ford Focus 2002 1 5 blue
2 Ford Focus 2002 2 5 blue
3 Ford Focus 2002 3 5 blue
4 Ford Focus 2002 4 5 blue
5 Ford kuga 2004 5 5 blue
6 Ford kuga 2004 1 5
7 Ford kuga 2004 2 5
8 Ford Mondeo 2004 3 5 red
9 Ford Mondeo 2004 4 4 red
10 Ford Mondeo 2004 5 red
11 Ford Mondeo 2004 6 red
12 Ford Mondeo 2004 7 4 red
13 Mercedes Benz 2010 1 3
14 Mercedes Benz 2010 1 3 white
15 Mercedes Benz 2010 1 5 Yellow
16 Mercedes 190E 2011 1 red
17 Mercedes 190E 2012 1 6
table 的最终输出是...
输出:
Row Car Model Date Sec Door Colour
1 Ford Focus 2002 1 5 blue
2 Ford Focus 2002 2 5 blue
3 Ford Focus 2002 3 5 blue
4 Ford Focus 2002 4 5 blue
5 Ford kuga 2004 5 5 blue
6 Ford kuga 2004 1 5 blue
7 Ford kuga 2004 2 5 blue
8 Ford Mondeo 2004 3 5 red
9 Ford Mondeo 2004 4 4 red
10 Ford Mondeo 2004 5 4 red
11 Ford Mondeo 2004 6 4 red
12 Ford Mondeo 2004 7 4 red
13 Mercedes Benz 2010 1 3 red
14 Mercedes Benz 2010 1 3 white
15 Mercedes Benz 2010 1 5 Yellow
16 Mercedes 190E 2011 1 5 red
17 Mercedes 190E 2012 1 6 red
它是怎么做到的?谢谢
UPDATE 技巧将产生您显示的输出。
data cars;
retain dummyby 1;
infile cards firstobs=2;
input row car $ model $ date sex door colour $;
cards;
Row Car Model Date Sec Door Colour
1 Ford Focus 2002 1 5 blue
2 Ford Focus 2002 2 5 blue
3 Ford Focus 2002 3 5 blue
4 Ford Focus 2002 4 5 blue
5 Ford kuga 2004 5 5 blue
6 Ford kuga 2004 1 5 .
7 Ford kuga 2004 2 5 .
8 Ford Mondeo 2004 3 5 red
9 Ford Mondeo 2004 4 4 red
10 Ford Mondeo 2004 5 . red
11 Ford Mondeo 2004 6 . red
12 Ford Mondeo 2004 7 4 red
13 Mercedes Benz 2010 1 3 .
14 Mercedes Benz 2010 1 3 white
15 Mercedes Benz 2010 1 5 Yellow
16 Mercedes 190E 2011 1 . red
17 Mercedes 190E 2012 1 6 .
;;;;
run;
data locf;
update cars(obs=0) cars;
by dummyby; *Use BY CAR; to LOCF for each car.;
output;
drop dummyby;
run;
proc print;
run;
主键是car、model和date,我要用之前的数据填空字段,但是它的主键是car和model。 示例:
Row Car Model Date Sec Door Colour
1 Ford Focus 2002 1 5 blue
2 Ford Focus 2002 2 5 blue
3 Ford Focus 2002 3 5 blue
4 Ford Focus 2002 4 5 blue
5 Ford kuga 2004 5 5 blue
6 Ford kuga 2004 1 5
7 Ford kuga 2004 2 5
8 Ford Mondeo 2004 3 5 red
9 Ford Mondeo 2004 4 4 red
10 Ford Mondeo 2004 5 red
11 Ford Mondeo 2004 6 red
12 Ford Mondeo 2004 7 4 red
13 Mercedes Benz 2010 1 3
14 Mercedes Benz 2010 1 3 white
15 Mercedes Benz 2010 1 5 Yellow
16 Mercedes 190E 2011 1 red
17 Mercedes 190E 2012 1 6
table 的最终输出是...
输出:
Row Car Model Date Sec Door Colour
1 Ford Focus 2002 1 5 blue
2 Ford Focus 2002 2 5 blue
3 Ford Focus 2002 3 5 blue
4 Ford Focus 2002 4 5 blue
5 Ford kuga 2004 5 5 blue
6 Ford kuga 2004 1 5 blue
7 Ford kuga 2004 2 5 blue
8 Ford Mondeo 2004 3 5 red
9 Ford Mondeo 2004 4 4 red
10 Ford Mondeo 2004 5 4 red
11 Ford Mondeo 2004 6 4 red
12 Ford Mondeo 2004 7 4 red
13 Mercedes Benz 2010 1 3 red
14 Mercedes Benz 2010 1 3 white
15 Mercedes Benz 2010 1 5 Yellow
16 Mercedes 190E 2011 1 5 red
17 Mercedes 190E 2012 1 6 red
它是怎么做到的?谢谢
UPDATE 技巧将产生您显示的输出。
data cars;
retain dummyby 1;
infile cards firstobs=2;
input row car $ model $ date sex door colour $;
cards;
Row Car Model Date Sec Door Colour
1 Ford Focus 2002 1 5 blue
2 Ford Focus 2002 2 5 blue
3 Ford Focus 2002 3 5 blue
4 Ford Focus 2002 4 5 blue
5 Ford kuga 2004 5 5 blue
6 Ford kuga 2004 1 5 .
7 Ford kuga 2004 2 5 .
8 Ford Mondeo 2004 3 5 red
9 Ford Mondeo 2004 4 4 red
10 Ford Mondeo 2004 5 . red
11 Ford Mondeo 2004 6 . red
12 Ford Mondeo 2004 7 4 red
13 Mercedes Benz 2010 1 3 .
14 Mercedes Benz 2010 1 3 white
15 Mercedes Benz 2010 1 5 Yellow
16 Mercedes 190E 2011 1 . red
17 Mercedes 190E 2012 1 6 .
;;;;
run;
data locf;
update cars(obs=0) cars;
by dummyby; *Use BY CAR; to LOCF for each car.;
output;
drop dummyby;
run;
proc print;
run;