我有数据集dat.txt(部分,只列前3行)形如
no chn math eng
1 93 88 74
2 65 33 90
3 78 69 83
我想把它变成
id subject score
1 chn 93
1 math 88
1 eng 74
2 chn 65
2 math 33
2 eng 90
3 chn 78
3 math 69
3 eng 83
R语言我相对比较熟悉
dat1=read.table("dat.txt",head=T)
dat1=dat1[,-1]
n=dim(dat1)[1]
p=dim(dat1)[2]
id=gl(p,n)
subject=rep(names(dat1),n)
score=as.vector(t(dat1))
dat2=data.frame(id,subject,score)
sas语言我才接触不久,该如何实现呢?我只开了个头
DATA dat1;
INFILE 'dat.txt' firstobs=2;
INPUT no chn math eng;
RUN;