<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Concatenating rows into one variable based on groups in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-rows-into-one-variable-based-on-groups/m-p/68250#M14788</link>
    <description>Hello,&lt;BR /&gt;
&lt;BR /&gt;
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:&lt;BR /&gt;
&lt;BR /&gt;
%macro group_concat(in_Group);&lt;BR /&gt;
	%global jobs='';&lt;BR /&gt;
		proc sql noprint;&lt;BR /&gt;
		select benchmark_job&lt;BR /&gt;
        		into :jobs separated by ', '&lt;BR /&gt;
        		from benchmark_lookup&lt;BR /&gt;
		where NAICS = &amp;amp;in_Group;&lt;BR /&gt;
		quit;&lt;BR /&gt;
		run;&lt;BR /&gt;
%mend group_concat;&lt;BR /&gt;
&lt;BR /&gt;
proc fcmp outlib=sasuser.funcs.concat trace print;&lt;BR /&gt;
		function ft_group_concat(in_Group$) $ 200;&lt;BR /&gt;
		rc = run_macro('group_concat',in_Group);&lt;BR /&gt;
		if rc = 0 then return(jobs);&lt;BR /&gt;
		else return('error');&lt;BR /&gt;
	endsub;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data _null_ ;&lt;BR /&gt;
	in_Group = '111, 113, 115';&lt;BR /&gt;
	macro_jobs = ft_group_concat(in_Group);&lt;BR /&gt;
	put jobs=;&lt;BR /&gt;
	put macro_jobs;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Thanks!</description>
    <pubDate>Wed, 02 Feb 2011 18:39:14 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2011-02-02T18:39:14Z</dc:date>
    <item>
      <title>Concatenating rows into one variable based on groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-rows-into-one-variable-based-on-groups/m-p/68250#M14788</link>
      <description>Hello,&lt;BR /&gt;
&lt;BR /&gt;
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:&lt;BR /&gt;
&lt;BR /&gt;
%macro group_concat(in_Group);&lt;BR /&gt;
	%global jobs='';&lt;BR /&gt;
		proc sql noprint;&lt;BR /&gt;
		select benchmark_job&lt;BR /&gt;
        		into :jobs separated by ', '&lt;BR /&gt;
        		from benchmark_lookup&lt;BR /&gt;
		where NAICS = &amp;amp;in_Group;&lt;BR /&gt;
		quit;&lt;BR /&gt;
		run;&lt;BR /&gt;
%mend group_concat;&lt;BR /&gt;
&lt;BR /&gt;
proc fcmp outlib=sasuser.funcs.concat trace print;&lt;BR /&gt;
		function ft_group_concat(in_Group$) $ 200;&lt;BR /&gt;
		rc = run_macro('group_concat',in_Group);&lt;BR /&gt;
		if rc = 0 then return(jobs);&lt;BR /&gt;
		else return('error');&lt;BR /&gt;
	endsub;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data _null_ ;&lt;BR /&gt;
	in_Group = '111, 113, 115';&lt;BR /&gt;
	macro_jobs = ft_group_concat(in_Group);&lt;BR /&gt;
	put jobs=;&lt;BR /&gt;
	put macro_jobs;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Thanks!</description>
      <pubDate>Wed, 02 Feb 2011 18:39:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenating-rows-into-one-variable-based-on-groups/m-p/68250#M14788</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2011-02-02T18:39:14Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating rows into one variable based on groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-rows-into-one-variable-based-on-groups/m-p/68251#M14789</link>
      <description>Try adding this to the FCMP function block;&lt;BR /&gt;
&lt;BR /&gt;
outargs jobs;

Message was edited by: Curtis Mack</description>
      <pubDate>Wed, 02 Feb 2011 19:00:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenating-rows-into-one-variable-based-on-groups/m-p/68251#M14789</guid>
      <dc:creator>CurtisMack</dc:creator>
      <dc:date>2011-02-02T19:00:20Z</dc:date>
    </item>
  </channel>
</rss>

