MySQL下group_concat函数的SAS实现
MySQL下的字符串聚合函数group_concat是一个非常实用的字符串合并函数, sas下的宏实现,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
%macro group_concat(input, output, id, string, length); data &output (drop=string_old); set &input (rename=(&string=string_old)); by &id; retain &string; length &string $ &length; * set large enough to accommodate the maximum number of records per ID; if first.&id then &string = ''; brand = catx(',',trim(&string),string_old); if last.&id then output; run; %mend group_concat; |
基本表结构如下, 按字母排序的变量和属性列表 # 变量 类型 长度 输出格式 输入格式 标签 2 brand 字符 40 $40. $40. brand 1 customer_id 字符 …