Sas 将数据从长格式重新构造为宽格式
嗨,我正在尝试使用一个数据步骤和一个数组来从长格式转换为宽格式。最初我的表是宽格式的,我知道如何使它成为长格式,但现在我需要使用数组使它再次变宽。当我运行上一个数据步骤的代码时,我得到一个包含空Expense1、Expense2、Expense3等列的表。我的桌子需要看起来像这样,但是有九个酒店和六个费用栏 求助 费用1 费用2 费用3 费用4 1号酒店 $165.89 $45.50 $78.00 $56.25 2号酒店 $215.32 $64.00 $54.00 $62.50Sas 将数据从长格式重新构造为宽格式,sas,Sas,嗨,我正在尝试使用一个数据步骤和一个数组来从长格式转换为宽格式。最初我的表是宽格式的,我知道如何使它成为长格式,但现在我需要使用数组使它再次变宽。当我运行上一个数据步骤的代码时,我得到一个包含空Expense1、Expense2、Expense3等列的表。我的桌子需要看起来像这样,但是有九个酒店和六个费用栏 求助 费用1 费用2 费用3 费用4 1号酒店 $165.89 $45.50 $78.00 $56.25 2号酒店 $215.32 $64.00 $54.00 $62.50 基于阵列的分组换
基于阵列的分组换位可按如下方式完成:
data wide(keep=resort expense1-expense6);
if 0 then set tall (keep=resort); * prep PDV with resort variable;
array expenses expenses1-expenses6; * prep PDV with wide variables;
* reset array to zeroes, resorts without a specific expenseID will have a 0;
do index = 1 to dim(expenses);
expenses[index] = 0;
end;
* if you want missing values instead of zeroes;
* call missing (of expenses(*));
* dow loop, iterate down the by group;
do until (last.resort);
set tall;
by resort;
expenses[expenseID] = expense;
end;
*implicit output, one row per resort;
run;