简体   繁体   English

重新排列SAS中的数据集

[英]Rearranging data set in SAS

I am new to SAS and am trying to rearrange a dataset. 我是SAS的新手,正在尝试重新排列数据集。 I feel that it shouldn't be too hard but I've been struggling with it for quite some time now. 我觉得它应该不会太难,但我已经在很长一段时间里一直在努力。 Here is what my dataset looks like 这是我的数据集的样子

Factor Variable Value
A      X        1
A      Y        2
B      X        3
B      Y        4

and I want my resulting dataset to be 我想要我的结果数据集

Variable   A   B
X          1   3
Y          2   4

Is this possible? 这可能吗? Thank you for your help. 谢谢您的帮助。

You want values of variable Value (VAR) to be transposed to columns that will be named by values of Factor (ID) for each value of Variable (BY) , while not keeping the name of Value in an output field _NAME_ (drop=_NAME_ ). 您希望将变量Value (VAR)转换为将由Variable (BY)每个值的Factor (ID)值命名的列,而不在输出字段中_NAME_ (drop=_NAME_ Value的名称_NAME_ (drop=_NAME_ )。 I do admit I always need to play with it to get what I need. 我承认我总是需要玩它才能得到我需要的东西。

data in;
length Factor Variable $1 Value 8;
input Factor Variable Value;
cards;
A      X        1
A      Y        2
B      X        3
B      Y        4
;
run;

proc sort data=in;
BY Variable;
run;

proc transpose data=in out=transp (drop=_NAME_);
ID Factor;
BY Variable;
VAR value;
run;

proc print noobs;run;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM