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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 1510 views
  • 0 likes
  • 2 in conversation