DATA Step, Macro, Functions and more

Concatenating rows into one variable based on groups

Reply
N/A
Posts: 0

Concatenating rows into one variable based on groups

Hello,

I'm trying to concatenate values in a column for each distinct value of a field in a different column of the same table. I've looked at some code snippets, but nothing seems to work. I'm not sure if it's a variable scope or timing issue, but here is the code I am trying to run:

%macro group_concat(in_Group);
%global jobs='';
proc sql noprint;
select benchmark_job
into :jobs separated by ', '
from benchmark_lookup
where NAICS = &in_Group;
quit;
run;
%mend group_concat;

proc fcmp outlib=sasuser.funcs.concat trace print;
function ft_group_concat(in_Group$) $ 200;
rc = run_macro('group_concat',in_Group);
if rc = 0 then return(jobs);
else return('error');
endsub;
run;

data _null_ ;
in_Group = '111, 113, 115';
macro_jobs = ft_group_concat(in_Group);
put jobs=;
put macro_jobs;
run;

Thanks!
Frequent Contributor
Posts: 102

Re: Concatenating rows into one variable based on groups

Try adding this to the FCMP function block;

outargs jobs; Message was edited by: Curtis Mack
Ask a Question
Discussion stats
  • 1 reply
  • 783 views
  • 0 likes
  • 2 in conversation