将多行组合成单行SAS

时间:2018-02-12 19:39:09

标签: sas transpose

我有以下数据集,我希望将变量'summary'转换并创建为变量

Date               serNo      source      summary      OrderNo
28SEP2017    101            CO            Number       123
28SEP2017    101            CO            City              Albany

输出数据集应该类似于

 Date               serNo      source      Number   City
 28SEP2017    101            CO           123      Albany

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:3)

by Proc sql

 proc sql;
 select distinct date, serno, source, 
 max(case when summary = 'Number' then Orderno end) as Number,
 max(case when summary = 'City' then orderno end) as city
 from have
 group by date, serno, source;

或通过proc转置

 proc sort data=have ;
 by date serno source;
 run;

 proc transpose data=have out=want(drop = _name_);
 by  date serno source;
 id summary;
 var orderno;
 run;