DATA Step, Macro, Functions and more

SAS version of Oracles LISTAGG function

Accepted Solution Solved
Reply
Contributor
Posts: 57
Accepted Solution

SAS version of Oracles LISTAGG function

Hi,

 

I wonder if anyone has an answer to Oracles LISTAGG function for SAS?

 

I'm using base SAS programming 7.1 & need some examples if anyone can help.

 

I've seen some examples using the 'BY' process.

 

Does anyone have any clear examples?

 

Thanks


Accepted Solutions
Solution
‎08-01-2016 05:15 AM
PROC Star
Posts: 1,563

Re: SAS version of Oracles LISTAGG function

SAS doesn't have summary functions for strings, sadly.

So you'll have to code it. For example:

 

data CLASS (index=(SEX));
  set SASHELP.CLASS;
run;
data T;
  length NAMES $200;
  retain NAMES;
  set CLASS;
  by SEX;
  if first.SEX then NAMES='';
  NAMES=catx(',',NAMES, NAME) ;
  if last.SEX then putlog NAMES=;
run;

NAMES=Alice,Barbara,Carol,Jane,Janet,Joyce,Judy,Louise,Mary

NAMES=Alfred,Henry,James,Jeffrey,John,Philip,Robert,Ronald,Thomas,William

 

 

 

 

View solution in original post


All Replies
Solution
‎08-01-2016 05:15 AM
PROC Star
Posts: 1,563

Re: SAS version of Oracles LISTAGG function

SAS doesn't have summary functions for strings, sadly.

So you'll have to code it. For example:

 

data CLASS (index=(SEX));
  set SASHELP.CLASS;
run;
data T;
  length NAMES $200;
  retain NAMES;
  set CLASS;
  by SEX;
  if first.SEX then NAMES='';
  NAMES=catx(',',NAMES, NAME) ;
  if last.SEX then putlog NAMES=;
run;

NAMES=Alice,Barbara,Carol,Jane,Janet,Joyce,Judy,Louise,Mary

NAMES=Alfred,Henry,James,Jeffrey,John,Philip,Robert,Ronald,Thomas,William

 

 

 

 

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 311 views
  • 1 like
  • 2 in conversation