【问题标题】:combining two columns separated by semicolons in SAS在SAS中组合用分号分隔的两列
【发布时间】:2014-04-29 09:48:56
【问题描述】:

我有以下数据集

ID  REGION  NUMTYPE
NY  us;ne   1015; 10x16
BO  us;ne   1015; 10x17
ID  nonus   1018

我想添加另一列“REGION_NUMTYPE”,其中包含由“;”分隔的每行区域和 num 类型的所有组合

ID  REGION  NUMTYPE             REGION_NUMTYPE
NY  us;ne   1015; 10x16     us1015; us10x16;ne1015;ne10x16
BO  us;ne   1015; 10x17     us1015; us10x17;ne1015;ne10x17
ID  nonus   1018                nonus1018

有没有简单的方法来做到这一点?非常感谢您的帮助

【问题讨论】:

    标签: sas


    【解决方案1】:

    最简单的方法是双循环。

    data want;
    set have;
    format Region_NumType $2000.; /*Modify size if needed*/
    
    
    do i=1 to countw(region,";");
       do j=1 to countw(NumType,";");
          Region_NumType = cats(Region_NumType,scan(region,i,";"),scan(NumType,j,";"),";");
       end;
    end;
    
    run;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-07
      • 1970-01-01
      • 1970-01-01
      • 2021-07-15
      • 1970-01-01
      相关资源
      最近更新 更多