我有一个像这样的sas日期库:
id birthday Date1 Date2
1 12/4/01 12/4/13 12/3/14
2 12/3/01 12/6/13 12/2/14
3 12/9/01 12/4/03 12/9/14
4 12/8/13 12/3/14 12/10/16
我想要这种形式的数据:
id Date Datetype
1 12/4/01 birthday
1 12/4/13 1
1 12/3/14 2
2 12/3/01 birthday
2 12/6/13 1
2 12/2/14 2
3 12/9/01 birthday
3 12/4/03 1
3 12/9/14 2
4 12/8/13 birthday
4 12/3/14 1
4 12/10/16 2
感谢您的帮助,我第二周就使用sas <3 编辑:谢谢仍然我,我没有找到一种排序方法。
答案 0 :(得分:0)
美好的一天。以下是您所追求的。我没有想出一种简单的方法来重命名列,因为它们不在起始数据中。
/*Data generation for ease of testing*/
data begin;
input id birthday $ Date1 $ Date2 $;
cards;
1 12/4/01 12/4/13 12/3/14
2 12/3/01 12/6/13 12/2/14
3 12/9/01 12/4/03 12/9/14
4 12/8/13 12/3/14 12/10/16
; run;
/*The trick here is to use date: The colon means everything beginning with date, comparae with sql 'date%'*/
proc transpose data= begin out=trans;
by id;
var birthday date: ;
run;
/*Cleanup. Renaming the columns as you wanted.*/
data trans;
set trans;
rename _NAME_= Datetype COL1= Date;
run;
的更多信息
答案 1 :(得分:0)
两个步骤
Proc TRANSPOSE
透视数据。PROC DATASETS
示例代码
proc transpose
data=have
out=want
( keep=id _label_ col1)
;
by id;
var birthday date1 date2;
label birthday='birthday' date1='1' date2='2' ; * Trick to force values seen in pivot;
run;
proc datasets noprint lib=work;
modify want;
rename
_label_ = Datetype
col1 = Date
;
label
Datetype = 'Datetype'
;
run;
TRANSPOSE输出表中的列顺序为:
_name_
和_label_
样本“ want”显示了_label_
/ _name_
列之前的数据列。更改基础列顺序的唯一方法是重写数据集。您可以通过使用其他数据视图或允许您指定所需特定顺序的输出Proc来更改查看该顺序时的感觉。