当所有变量都具有所需的后缀时,在 sas 中将宽转换为长 [英] Covert wide to long in sas when all the variable has the suffix needed

查看:34
本文介绍了当所有变量都具有所需的后缀时,在 sas 中将宽转换为长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望第一个宽数据集作为第二个长数据文件,我曾考虑使用数组,但考虑到我有 100 个变量(示例只有 2 个),我需要 100 个数组吗?

I want the first wide dataset to be as the second long datafile, I have thought about using array, but considering I have 100 variables (the example only have 2), do I need 100 arrays?

你能告诉我怎么做吗?

推荐答案

使用双转置.首先转置到一个高大的结构.然后将名称拆分为基本名称和时间.然后再次转置.这是未经测试的代码,因为没有提供示例数据(只有照片).

Use a double transpose. First transpose to a tall structure. Then split the name into the basename and time. Then transpose again. Here is untested code since no example data was provided (only photographs).

proc transpose data=have out=tall ;
  by id;
  var _numeric_;
run;
data fixed ;
   set tall ;
   time = scan(_name_,-1,'_');
   _name_ = substr(_name_,1,length(_name_)-length(time)-1);
run;
proc sort data=fixed ;
  by id time;
run;
proc transpose data=fixed out=want ;
  by id time ;
  id _name_;
  var col1;
run;

这篇关于当所有变量都具有所需的后缀时,在 sas 中将宽转换为长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆