sas - 如何通过观察数据步骤将我的数据转置在 sas 上
问题描述
我有一个类似这样的 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 编辑:感谢我,我没有找到排序方法。
解决方案
再会。以下应该是您所追求的。我没有想出一种简单的方法来重命名列,因为它们不在起始数据中。
/*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;
从肯特大学网站查看更多信息
推荐阅读
- sql - SQL sum 和上一行
- c# - SignalR 集线器客户端无法在 SignalR 管道外部正确解析
- cups - 无法使用 cups4j 从杯子 2.0.1 中获取纸张颜色
- selenium - 如何在 Jenkins 上运行 CI selenium side runner 测试
- javascript - 合并 2 个数组,更新值
- .net-core - 无法使用 FormattableString
- c++ - 为什么我得到
() 函数不能接收元组的子类? - python - Airflow:原生运营商与容器
- perl - 如何使用 Mojo::Useragent 放置文件?
- sql - 使用 Laravel 和 SQL Server 在事务中插入具有不同数据类型的语句失败