在SAS中从一列生成字符串

在SAS中从一列生成字符串,sas,proc-sql,Sas,Proc Sql,我在SAS中有一个数据集,我想按产品将一列转换为字符串。我已附上输入和输出所需的图像。 我需要在输出端插入列字符串。有人能帮我吗 我编写了一个数据步骤来创建输入数据: data have; input products $ dates value ; datalines; a 1 0 a 2 0 a 3 1 a 4 0 a 5 1 a 6 1 b 1 0 b 2 1 b 3 1 b 4 1 b 5 0 b 6 0 c 1 1 c 2 0 c

我在SAS中有一个数据集,我想按产品将一列转换为字符串。我已附上输入和输出所需的图像。 我需要在输出端插入列字符串。有人能帮我吗


我编写了一个数据步骤来创建输入数据:

data have;
   input products $
         dates
         value
   ;

   datalines;
a 1 0
a 2 0
a 3 1
a 4 0
a 5 1
a 6 1
b 1 0
b 2 1
b 3 1
b 4 1
b 5 0
b 6 0
c 1 1
c 2 0
c 3 1
c 4 1
c 5 0
c 6 1
;
以下建议的解决方案是否满足您的需求

data want;
   length string $ 20;

   do until(last.products);
      set have;
      by products;

      string = catx(',',string,value);
   end;

   do until(last.products);
      set have;
      by products;

      output;
   end;
run;

这是我的快速解决方案


Stackoverflow不是代码编写服务。你试过什么?您得到了什么错误或意外输出?@Richard我尝试使用RETAIN函数,但没有按预期工作。下一次,我将为上下文提供代码。
data temp;
  length cat $20.;
  do until (last.prod);
    set have;
    by prod notsorted;
   cat=catx(',',cat,value);
  end;

  drop value date;
run;

proc sql;
  create table want as
  select have.*, cat as string
  from have inner join temp
  on have.prod=temp.prod;
quit;