<?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 populate variables from a table and loop the program in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/populate-variables-from-a-table-and-loop-the-program/m-p/476878#M30965</link>
    <description>&lt;P&gt;I have a project that pulls data from 3 DB2 tables and 1 Oracle table based on a prompt value.&amp;nbsp; The prompt contains a bank id used to relate all the data together.&amp;nbsp; This works well after the local prompt is converted to a global prompt.&amp;nbsp; The value of the prompt can be altered and the proper report produced.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The next step is to replace the single prompt with a variable taken from a table (Bank_ID) of more than 10 banks, take one bank id at a time, run the program which produces an Excel report, select the next bank id from the table (Bank_ID), run program, produce new report....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am looking for suggestions on how to take a single field from each observation in the SAS table&amp;nbsp;(Bank_ID)&amp;nbsp;run the project and repeat until all observations are processed.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Due to my lack of experience (learning on the fly) with EG I am struggling with this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 10 Jul 2018 17:39:30 GMT</pubDate>
    <dc:creator>RAW_newbie</dc:creator>
    <dc:date>2018-07-10T17:39:30Z</dc:date>
    <item>
      <title>populate variables from a table and loop the program</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/populate-variables-from-a-table-and-loop-the-program/m-p/476878#M30965</link>
      <description>&lt;P&gt;I have a project that pulls data from 3 DB2 tables and 1 Oracle table based on a prompt value.&amp;nbsp; The prompt contains a bank id used to relate all the data together.&amp;nbsp; This works well after the local prompt is converted to a global prompt.&amp;nbsp; The value of the prompt can be altered and the proper report produced.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The next step is to replace the single prompt with a variable taken from a table (Bank_ID) of more than 10 banks, take one bank id at a time, run the program which produces an Excel report, select the next bank id from the table (Bank_ID), run program, produce new report....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am looking for suggestions on how to take a single field from each observation in the SAS table&amp;nbsp;(Bank_ID)&amp;nbsp;run the project and repeat until all observations are processed.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Due to my lack of experience (learning on the fly) with EG I am struggling with this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jul 2018 17:39:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/populate-variables-from-a-table-and-loop-the-program/m-p/476878#M30965</guid>
      <dc:creator>RAW_newbie</dc:creator>
      <dc:date>2018-07-10T17:39:30Z</dc:date>
    </item>
    <item>
      <title>Re: populate variables from a table and loop the program</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/populate-variables-from-a-table-and-loop-the-program/m-p/476884#M30966</link>
      <description>&lt;P&gt;You probably want a macro and then to use CALL EXECUTE to call the macro from the data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is easier via code, no idea how you would loop a process flow.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DO you have a specific program or are you using the process flow?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jul 2018 17:45:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/populate-variables-from-a-table-and-loop-the-program/m-p/476884#M30966</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-07-10T17:45:34Z</dc:date>
    </item>
    <item>
      <title>Re: populate variables from a table and loop the program</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/populate-variables-from-a-table-and-loop-the-program/m-p/476887#M30967</link>
      <description>&lt;P&gt;As Reeza says, there is no looping mechanism in the process flow.&amp;nbsp; To scale this you will probably need to convert to an all-code approach.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/51532"&gt;@LeonidBatkhan&lt;/a&gt;&amp;nbsp;wrote &lt;A href="https://blogs.sas.com/content/sgf/2017/08/02/call-execute-for-sas-data-driven-programming/" target="_self"&gt;a nice article about how to use CALL EXECUTE in this way&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(It is possible to "loop" in EG via automation...but that's probably a topic for another day.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jul 2018 17:49:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/populate-variables-from-a-table-and-loop-the-program/m-p/476887#M30967</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2018-07-10T17:49:00Z</dc:date>
    </item>
    <item>
      <title>Re: populate variables from a table and loop the program</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/populate-variables-from-a-table-and-loop-the-program/m-p/480021#M31140</link>
      <description>&lt;P&gt;What I was looking for is detailed below.&amp;nbsp; Right now it is a task in a project which uses an %include to execute SAS code to produce 10 reports based on an ID number from a table.&amp;nbsp; It loops through 10 observations in the table based on a where statement to isolate the 10 observations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Each observation is passed in a variable to the SAS code to query 6 tables in two different operating systems.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
/*..Build a dataset to be a row-level driver of a separate SAS program. */
proc sql;
&amp;nbsp;CREATE TABLE WORK.SCHOOL_ID1 AS
&amp;nbsp;SELECT *
&amp;nbsp;FROM WORK.SCHOOL_ID_LIST_01
&amp;nbsp;WHERE ORG_LIST LIKE 'S%';
quit;

/*..Add a row number to the SCHOOL_ID dataset. */
data WORK.SCHOOL_ID1_Dataset;
&amp;nbsp; set WORK.SCHOOL_ID1;
&amp;nbsp; RowNumber = _n_;
run;

/*..Count the number of rows in the SCHOOL_ID dataset. */
proc sql noprint;
&amp;nbsp; select count(*) into :SCHOOL_ID_RowCount
&amp;nbsp; from WORK.SCHOOL_ID1_Dataset;
quit;
%put SCHOOL_ID_RowCount = &amp;amp;SCHOOL_ID_RowCount;

%macro SCHOOL_ID_ProcessRow(RowNumber=);
&amp;nbsp; proc sql noprint;
&amp;nbsp;&amp;nbsp;&amp;nbsp; select SCHOOL_ID_LIST into :SCHOOL_ID
&amp;nbsp;&amp;nbsp;&amp;nbsp; from work.SCHOOL_ID1_Dataset
&amp;nbsp;&amp;nbsp;&amp;nbsp; where RowNumber = &amp;amp;RowNumber;
&amp;nbsp; quit;
&amp;nbsp; %put For RowNumber=&amp;amp;RowNumber;
&amp;nbsp; %put SCHOOL_ID=&amp;amp;SCHOOL_ID;
&amp;nbsp;
&amp;nbsp;%include '...include sas code using the variable SCHOOL_ID';

%mend SCHOOL_ID_ProcessRow;

/*..Loop thru each row of the SCHOOL_ID dataset. */
%macro SCHOOL_ID_Loop;
&amp;nbsp; %do SCHOOL_ID_RowNum = 1 %to &amp;amp;SCHOOL_ID_RowCount;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %SCHOOL_ID_ProcessRow(RowNumber=&amp;amp;SCHOOL_ID_RowNum);
&amp;nbsp; %end;
%mend SCHOOL_ID_Loop;
%SCHOOL_ID_Loop;

&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jul 2018 19:27:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/populate-variables-from-a-table-and-loop-the-program/m-p/480021#M31140</guid>
      <dc:creator>RAW_newbie</dc:creator>
      <dc:date>2018-07-20T19:27:51Z</dc:date>
    </item>
    <item>
      <title>Re: populate variables from a table and loop the program</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/populate-variables-from-a-table-and-loop-the-program/m-p/480047#M31142</link>
      <description>&lt;P&gt;That might work for you, but it could be so much less complex with fewer macro constructs, if you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First, you can get the count of a list from PROC SQL by assigning the &amp;amp;SQLOBS macro variable, automatically generated.&amp;nbsp; &lt;A href="https://blogs.sas.com/content/sasdummy/2017/03/27/sqlobs-record-count/" target="_self"&gt;See How many records are in that PROC SQL result?&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Next, there are two main patterns that SAS programmers use when having to repeat a process for each record or for every value of a grouping variable:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="https://blogs.sas.com/content/sasdummy/2012/03/20/sas-program-by-processing/" target="_self"&gt;Implement BY processing for your entire SAS program&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://blogs.sas.com/content/sgf/2017/08/02/call-execute-for-sas-data-driven-programming/" target="_self"&gt;CALL EXECUTE for data driven programming&lt;/A&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;I think that either one of these would save you from having one macro that has to call another macro within a macro loop.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jul 2018 19:38:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/populate-variables-from-a-table-and-loop-the-program/m-p/480047#M31142</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2018-07-20T19:38:55Z</dc:date>
    </item>
  </channel>
</rss>

