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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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