<?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 Union using Loop - Macro Variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Union-using-Loop-Macro-Variables/m-p/319434#M70158</link>
    <description>&lt;P&gt;I've got the following code that creates 30 datasets (6 * 5 channels).&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've got a loop going that creates all the datasets as I wish but now I'm stuck trying to find an efficient way to combine all the&lt;/P&gt;&lt;P&gt;sets without having to write it all out...&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestion???&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
CREATE TABLE CHANNEL 
(channel char(8));
insert into channel 
values ("ALL")
values ("ChannelF")
values ("ChannelG")
values ("ChannelH")
values ("ChannelI");

PROC SQL noprint;
select channel
into :channel1 - :channel5 notrim
from channel;
quit;

%macro putit;
%do i=1 %to i=5;
%put Row&amp;amp;i: Channel = &amp;amp;&amp;amp;channel&amp;amp;i;
%end;
%mend putit;
%putit


%macro average;
%do i=1 %to 5;
/*Canada - Received */
PROC SQL;
CREATE TABLE AVGRECCAN_&amp;amp;&amp;amp;channel&amp;amp;i AS SELECT
REPORTING, YRQRT, "CANADA" AS REGIONID, "RECEIVED" AS CATEGORY, GROUP,
AVG(bestscore) as AVG_SCORE
FROM &amp;amp;&amp;amp;channel&amp;amp;i
GROUP BY REPORTING, YRQRT, GROUP;
QUIT;
/*Toronto - Received */
PROC SQL;
CREATE TABLE AVGRECTORONTO_&amp;amp;&amp;amp;channel&amp;amp;i AS SELECT
REPORTING, YRQRT, "TORONTO" AS REGIONID, "RECEIVED" AS CATEGORY, GROUP,
AVG(bestscore) as AVG_SCORE
FROM &amp;amp;&amp;amp;channel&amp;amp;i
WHERE TORONTOIND ='TORONTO'
GROUP BY REPORTING, YRQRT, GROUP;
QUIT;
/*Provincial - Received*/
PROC SQL;
CREATE TABLE AVGRECPROV_&amp;amp;&amp;amp;channel&amp;amp;i AS SELECT
REPORTING, YRQRT, REGION AS REGIONID, "RECEIVED" AS CATEGORY, GROUP,
AVG(bestscore) as AVG_SCORE
FROM &amp;amp;&amp;amp;channel&amp;amp;i
GROUP BY REPORTING, YRQRT, GROUP,REGION ;
QUIT;
/*Canada - Approved*/
PROC SQL;
CREATE TABLE AVGAPPCAN_&amp;amp;&amp;amp;channel&amp;amp;i AS SELECT
REPORTING, YRQRT, "CANADA" AS REGIONID, "APPROVED" AS CATEGORY, GROUP,
AVG(bestscore) as AVG_SCORE
FROM &amp;amp;&amp;amp;channel&amp;amp;i
WHERE STATUS_IND = "APPROVED"
GROUP BY REPORTING, YRQRT, GROUP;
QUIT;
/*Toronto - Approved*/
PROC SQL;
CREATE TABLE AVGAPPTORONTO_&amp;amp;&amp;amp;channel&amp;amp;i AS SELECT
REPORTING, YRQRT, "TORONTO" AS REGIONID, "APPROVED" AS CATEGORY, GROUP,
AVG(bestscore) as AVG_SCORE
FROM &amp;amp;&amp;amp;channel&amp;amp;i
WHERE TORONTOIND ='TORONTO' AND STATUS_IND = "APPROVED"
GROUP BY REPORTING, YRQRT, GROUP;
QUIT;
/*Provincial - Approved*/
PROC SQL;
CREATE TABLE AVGAPPPROV_&amp;amp;&amp;amp;channel&amp;amp;i AS SELECT
REPORTING, YRQRT, REGION AS REGIONID, "APPROVED" AS CATEGORY, GROUP,
AVG(bestscore) as AVG_SCORE
FROM &amp;amp;&amp;amp;channel&amp;amp;i
WHERE STATUS_IND = "APPROVED"
GROUP BY REPORTING, YRQRT, GROUP,REGION ;
QUIT;

%end;
%mend average;
%average;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 16 Dec 2016 02:43:39 GMT</pubDate>
    <dc:creator>camfarrell25</dc:creator>
    <dc:date>2016-12-16T02:43:39Z</dc:date>
    <item>
      <title>Union using Loop - Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Union-using-Loop-Macro-Variables/m-p/319434#M70158</link>
      <description>&lt;P&gt;I've got the following code that creates 30 datasets (6 * 5 channels).&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've got a loop going that creates all the datasets as I wish but now I'm stuck trying to find an efficient way to combine all the&lt;/P&gt;&lt;P&gt;sets without having to write it all out...&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestion???&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
CREATE TABLE CHANNEL 
(channel char(8));
insert into channel 
values ("ALL")
values ("ChannelF")
values ("ChannelG")
values ("ChannelH")
values ("ChannelI");

PROC SQL noprint;
select channel
into :channel1 - :channel5 notrim
from channel;
quit;

%macro putit;
%do i=1 %to i=5;
%put Row&amp;amp;i: Channel = &amp;amp;&amp;amp;channel&amp;amp;i;
%end;
%mend putit;
%putit


%macro average;
%do i=1 %to 5;
/*Canada - Received */
PROC SQL;
CREATE TABLE AVGRECCAN_&amp;amp;&amp;amp;channel&amp;amp;i AS SELECT
REPORTING, YRQRT, "CANADA" AS REGIONID, "RECEIVED" AS CATEGORY, GROUP,
AVG(bestscore) as AVG_SCORE
FROM &amp;amp;&amp;amp;channel&amp;amp;i
GROUP BY REPORTING, YRQRT, GROUP;
QUIT;
/*Toronto - Received */
PROC SQL;
CREATE TABLE AVGRECTORONTO_&amp;amp;&amp;amp;channel&amp;amp;i AS SELECT
REPORTING, YRQRT, "TORONTO" AS REGIONID, "RECEIVED" AS CATEGORY, GROUP,
AVG(bestscore) as AVG_SCORE
FROM &amp;amp;&amp;amp;channel&amp;amp;i
WHERE TORONTOIND ='TORONTO'
GROUP BY REPORTING, YRQRT, GROUP;
QUIT;
/*Provincial - Received*/
PROC SQL;
CREATE TABLE AVGRECPROV_&amp;amp;&amp;amp;channel&amp;amp;i AS SELECT
REPORTING, YRQRT, REGION AS REGIONID, "RECEIVED" AS CATEGORY, GROUP,
AVG(bestscore) as AVG_SCORE
FROM &amp;amp;&amp;amp;channel&amp;amp;i
GROUP BY REPORTING, YRQRT, GROUP,REGION ;
QUIT;
/*Canada - Approved*/
PROC SQL;
CREATE TABLE AVGAPPCAN_&amp;amp;&amp;amp;channel&amp;amp;i AS SELECT
REPORTING, YRQRT, "CANADA" AS REGIONID, "APPROVED" AS CATEGORY, GROUP,
AVG(bestscore) as AVG_SCORE
FROM &amp;amp;&amp;amp;channel&amp;amp;i
WHERE STATUS_IND = "APPROVED"
GROUP BY REPORTING, YRQRT, GROUP;
QUIT;
/*Toronto - Approved*/
PROC SQL;
CREATE TABLE AVGAPPTORONTO_&amp;amp;&amp;amp;channel&amp;amp;i AS SELECT
REPORTING, YRQRT, "TORONTO" AS REGIONID, "APPROVED" AS CATEGORY, GROUP,
AVG(bestscore) as AVG_SCORE
FROM &amp;amp;&amp;amp;channel&amp;amp;i
WHERE TORONTOIND ='TORONTO' AND STATUS_IND = "APPROVED"
GROUP BY REPORTING, YRQRT, GROUP;
QUIT;
/*Provincial - Approved*/
PROC SQL;
CREATE TABLE AVGAPPPROV_&amp;amp;&amp;amp;channel&amp;amp;i AS SELECT
REPORTING, YRQRT, REGION AS REGIONID, "APPROVED" AS CATEGORY, GROUP,
AVG(bestscore) as AVG_SCORE
FROM &amp;amp;&amp;amp;channel&amp;amp;i
WHERE STATUS_IND = "APPROVED"
GROUP BY REPORTING, YRQRT, GROUP,REGION ;
QUIT;

%end;
%mend average;
%average;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Dec 2016 02:43:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Union-using-Loop-Macro-Variables/m-p/319434#M70158</guid>
      <dc:creator>camfarrell25</dc:creator>
      <dc:date>2016-12-16T02:43:39Z</dc:date>
    </item>
    <item>
      <title>Re: Union using Loop - Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Union-using-Loop-Macro-Variables/m-p/319443#M70163</link>
      <description>&lt;P&gt;Use a naming convention then you can use the colon wildcard to append all that start with the same prefix.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example this appends all tables that start with RECEIVED_.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data want;&lt;/P&gt;
&lt;P&gt;set received_:;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Dec 2016 04:27:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Union-using-Loop-Macro-Variables/m-p/319443#M70163</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-12-16T04:27:08Z</dc:date>
    </item>
    <item>
      <title>Re: Union using Loop - Macro Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Union-using-Loop-Macro-Variables/m-p/319488#M70184</link>
      <description>&lt;P&gt;Why are you doing that code at all? &amp;nbsp;I can't really tell what your underlying data is, but creating 6 * 5 datasets and then combining them seems to be mad. &amp;nbsp;Why create all those datasets, and then do&amp;nbsp;&lt;STRONG&gt;exactly&lt;/STRONG&gt; the same process on each of them and then combine them? &amp;nbsp;Why not combine your data in a useable model, then run the code&amp;nbsp;&lt;STRONG&gt;once&lt;/STRONG&gt; on that one dataset, using a by group if necessary:&lt;/P&gt;
&lt;PRE&gt;proc means data=allcombined;
  var avar;
  output out=want mean=mean;
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Dec 2016 10:19:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Union-using-Loop-Macro-Variables/m-p/319488#M70184</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-12-16T10:19:48Z</dc:date>
    </item>
  </channel>
</rss>

