BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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!
1 REPLY 1
CurtisMack
Fluorite | Level 6
Try adding this to the FCMP function block;

outargs jobs; Message was edited by: Curtis Mack

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 1607 views
  • 0 likes
  • 2 in conversation