SAS Proc SQL ---如何在SAS中做Listagg函数 [英] SAS Proc SQL --- how to do Listagg function in SAS

查看:84
本文介绍了SAS Proc SQL ---如何在SAS中做Listagg函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下午好

我正在使用 Proc SQL 在 SAS 上寻找 listagg 函数.

I am looking for listagg function on SAS by using Proc SQL.

例如

id         product_name
1001        Bananas
1002        Bananas
1002        Apples
1002        Peach
1003        Pears

proc sql;
create table work.test2 as
select id, _____(',', product_name)
from  test1
group by id
order by 1;
quit;

结果

    id          product_name

    1001        Bananas
    1002        Bananas,Apples,Peach
    1003        Pears

SAS里有这样的功能吗?

There is function like this in SAS?

推荐答案

你可以做的

data have;
input id product_name $;
datalines;
1001        Bananas
1002        Bananas
1002        Apples
1002        Peach
1003        Pears
 ;


  data want(rename=(product=product_name));
 do until(last.id);
 set have;
 by id;
 length product $50.;
  product =catx(',',product_name, product);
 end;
drop product_name;
run;

这篇关于SAS Proc SQL ---如何在SAS中做Listagg函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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