SAS使用以下字段读取输入文件

时间:2016-03-08 05:59:47

标签: sas

您好我有一个txt文件排列如下:

ID        Item1            Item2
x1        A                B
x2                         A  
x3        C                D
x4        A                 
x5        A                B 

文本文件中可能有空格。 ID都是唯一的数字。我希望他们在SAS中阅读如下:

ID item
x1 A 
x1 B
x2
x2 C and so on.....

我可以通过infile或其他方式来做到这一点吗?感谢

1 个答案:

答案 0 :(得分:0)

masterItem1加载到数组中,迭代&输出

data want ;
  infile "myfile.txt" ;
  input @1 ID $2. 
        @11 Item1 $1.
        @28 Item2 $1.
        ;

  array items{*} Item1-Item2 ;
  do i = 1 to dim(items) ;
    Item = items{i} ;
    output ;
  end ;

  drop Item1-Item2 ;
run ;