c********q 发帖数: 18 | 1 请教大家一个问题:
data如下:
78 70 79 78 77 78 69 72 73 75
79 76 66 80 76 78 68 77 71 77 83
78 76 70 72 75 72 76 73 72
66 66 74 64 69 67 70 75 70 68 69
64 72 65 66 70 75 81 70 66 76 71 70 75 73 72
74 81 79 76 71 81 70 75 77 75 72 73 90 65
83 80 84 84 84 82 82 84 82 81 79 81 76 81
85 85 87 85 96 85 86 85 85 95 84 85 84
每一行应该是15个数字,一共八行,每一行代表不同的含义:
Row 1 is the satisfaction of males flying Delta airlines
Row 2 is the satisfaction of females flying Delta airlines
Row 3 is the satisfaction of males flyingSouthwest airlines
Row 4 is the satisfaction of females flying Southwest airlines
Row 5 is the satisfaction of males flyingAmerican airlines
Row 6 is the satisfaction of females flying American airlines
Row 7 is the satisfaction of males flying United airlines
Row 8 is the satisfaction of females flying United airlines
然后要用loop进行整理把数据变成univariate,理想情况应该是
航空公司名字,性别,满意度
楼主写的code是这样的:
Data airline;
Infile 'C:UsersDownloadsairline.txt' DLM='' missover;
do carrier="delta airlines","southwest airlines","american airlines","united
airlines";
do sex="males","females";
do subj=1 to 15;
input rating @;
If rating=. then delete else output;
output;
end;
end;
end;
run;
proc print data=airline;
run;
但是运行出来全部变成了一个航空公司一个性别。。。
不知道code应该怎么改??
谢谢~~ | t*********g 发帖数: 136 | 2 数据量这么小的话,干嘛不手动修改一下格式再让sas读?
或者你一定要用程序读的话,我觉得比较简单的是下面这种方法。
不过你要知道每组的个数。
data test;
input values @@;
if 1 <= _N_ <= 10 then sex = 'M';
.........;
datalines;
78 70 79 78 77 78 69 72 73 75
.........
;
run; | s******8 发帖数: 102 | 3 如果你是想把同样的数据读给四个公司,试一下:
Data airline;
Infile 'C:UsersDownloadsairline.txt' DLM='' missover ;
if mod(_n_,2) eq 0 then sex='female';
else sex='male';
do subj=1 to 15;
input rating @;
If not missing(rating) then do carrier="delta airlines","southwest airlines
","american airlines","united
airlines";
output;
end;
end;
run; | s******8 发帖数: 102 | 4 or this is what you want.
Data airline;
length carrier car1-car4 $20.;
Infile datalines DLM='' missover ;
array car(4) $ ("delta airlines","southwest airlines","american airlines","
united airlines");
if mod(_n_,2) eq 0 then sex='female';
else sex='male';
do subj=1 to 15;
input rating @;
carrier=car(mod(subj-1,4)+1);
if not missing(rating) then output;
end;
drop subj car1-car4;
run; | m***c 发帖数: 118 | 5 下面的code是个简单的例子,你就把变量com加到5个,然后再把j=1 to 5换成15就可
以了。
data a(drop=j);
do com='United','Delta';
do sex= 'M','F';
do j=1 to 5;
input x @@;
output;
end;end;end;
cards;
19 18 10 16 12
21 24 20 27 26
37 39 32 35 31
40 47 43 45 44
;
run; |
|