<?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 Re: Execute a set of procedures &amp;quot;X&amp;quot; times. Each time change to the next number (file) in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Execute-a-set-of-procedures-quot-X-quot-times-Each-time-change/m-p/545931#M8121</link>
    <description>&lt;P&gt;Here are my suggestions:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Run your SAS programs as a batch job with the ERRORABEND option then you won't need an error checking macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Write a DATA step to construct a %INCLUDE statement to read in and run your series of procedures using CALL EXECUTE. This way you can avoid macros entirely. It would look something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  do Loop_Count = 1 to 50;
    exec_stmt = '%let filenumber = ' !! put(Loop_Count, 2.) !! 
                '; %include "MySASProgramFolder\MySASProgram.sas";';
    call execute('%nrstr(' !! exec_stmt !! ')');
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 25 Mar 2019 19:13:45 GMT</pubDate>
    <dc:creator>SASKiwi</dc:creator>
    <dc:date>2019-03-25T19:13:45Z</dc:date>
    <item>
      <title>Execute a set of procedures "X" times. Each time change to the next number (file)</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Execute-a-set-of-procedures-quot-X-quot-times-Each-time-change/m-p/545913#M8116</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a set of procedures or steps that runs in a row, the steps mainly consist in:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. Importing a file using proc import&lt;/P&gt;&lt;P&gt;2. Reshaping the file using a data set step.&lt;/P&gt;&lt;P&gt;3. Filtering data using data step&lt;/P&gt;&lt;P&gt;4. Export the file&amp;nbsp;using proc export&lt;/P&gt;&lt;P&gt;5. Rename last table used.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then start again with the next file.&amp;nbsp;&lt;/P&gt;&lt;P&gt;So far, I can do it manually, just changing the number of the file from 1 to two and then 3 and so on.&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let&amp;nbsp;filenumber&amp;nbsp;and&amp;nbsp;l%et tablename = _1&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I looking a way to do it automatically, If I have 50 files run everything 50 times for each file. I am not sure if I just need a do loop, or define a macro or maybe something else. I have also a macro that stops if an error appears in any step.&lt;/P&gt;&lt;P&gt;Can anyone point me out who to sort this problem out?. My fingers will really appreciate it.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The files are stored with numbers basically, therefore files&amp;nbsp;are named from 1 to 50.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let odata = _gf_income; * data name for importing first time ;
%let ldata = _long_gf_income; * data name where data is transform to long format ;
%let final = _final_gf_income; * final version containing just london stock exchange companies ;
%let filenumber = 1 ;
%let tablename = _1 ;
%let all_tables = all_incomestatements;
%macro check_for_errors;
   %if &amp;amp;syserr &amp;gt; 0 %then %do;
      %abort cancel;
   %end;
%mend check_for_errors;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2019 18:09:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Execute-a-set-of-procedures-quot-X-quot-times-Each-time-change/m-p/545913#M8116</guid>
      <dc:creator>OscarUvalle</dc:creator>
      <dc:date>2019-03-25T18:09:16Z</dc:date>
    </item>
    <item>
      <title>Re: Execute a set of procedures "X" times. Each time change to the next number (file)</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Execute-a-set-of-procedures-quot-X-quot-times-Each-time-change/m-p/545914#M8117</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/248392"&gt;@OscarUvalle&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi there,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a set of procedures or steps that runs in a row, the steps mainly consist in:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Importing a file using proc import&lt;/P&gt;
&lt;P&gt;2. Reshaping the file using a data set step. &lt;STRONG&gt;&lt;FONT color="#ff0000"&gt;Almost certain to fail sometimes as Proc import could guess differently for each file and code written to reshape one data set may fail on another.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;3. Filtering data using data step&lt;/P&gt;
&lt;P&gt;4. Export the file&amp;nbsp;using proc export&lt;/P&gt;
&lt;P&gt;5. Rename last table used.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then start again with the next file.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So far, I can do it manually, just changing the number of the file from 1 to two and then 3 and so on.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let&amp;nbsp;filenumber&amp;nbsp;and&amp;nbsp;l%et tablename = _1&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I looking a way to do it automatically, If I have 50 files run everything 50 times for each file. I am not sure if I just need a do loop, or define a macro or maybe something else. I have also a macro that stops if an error appears in any step.&lt;/P&gt;
&lt;P&gt;Can anyone point me out who to sort this problem out?. My fingers will really appreciate it.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The files are stored with numbers basically, therefore files&amp;nbsp;are named from 1 to 50.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let odata = _gf_income; * data name for importing first time ;
%let ldata = _long_gf_income; * data name where data is transform to long format ;
%let final = _final_gf_income; * final version containing just london stock exchange companies ;
%let filenumber = 1 ;
%let tablename = _1 ;
%let all_tables = all_incomestatements;
%macro check_for_errors;
   %if &amp;amp;syserr &amp;gt; 0 %then %do;
      %abort cancel;
   %end;
%mend check_for_errors;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If these files are supposed to have the same format then write a data step that will work to read all of the data files. Otherwise with proc import guessing as to variable type and length, and possibly even variable names any data step code to manipulate the result for your second and third steps has a high probability of failing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the data files are actually spread sheet the failure rate will go way up.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2019 18:14:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Execute-a-set-of-procedures-quot-X-quot-times-Each-time-change/m-p/545914#M8117</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-03-25T18:14:07Z</dc:date>
    </item>
    <item>
      <title>Re: Execute a set of procedures "X" times. Each time change to the next number (file)</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Execute-a-set-of-procedures-quot-X-quot-times-Each-time-change/m-p/545925#M8119</link>
      <description>&lt;P&gt;&lt;A href="https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md" target="_blank"&gt;https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;1. Develop the process for one file.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Convert to a macro for all files&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The tutorial above explains that concept.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As someone else has already mentioned, you could just read the file once, and use BY group processing to do it all at once. This is by far the most efficient method.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Write a data step to read all the files at once (assuming not Excel files, otherwise you need the process above).&lt;/P&gt;
&lt;P&gt;2. Change process to use BY groups&lt;/P&gt;
&lt;P&gt;3. Export to individual files&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/248392"&gt;@OscarUvalle&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi there,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a set of procedures or steps that runs in a row, the steps mainly consist in:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Importing a file using proc import&lt;/P&gt;
&lt;P&gt;2. Reshaping the file using a data set step.&lt;/P&gt;
&lt;P&gt;3. Filtering data using data step&lt;/P&gt;
&lt;P&gt;4. Export the file&amp;nbsp;using proc export&lt;/P&gt;
&lt;P&gt;5. Rename last table used.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then start again with the next file.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So far, I can do it manually, just changing the number of the file from 1 to two and then 3 and so on.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let&amp;nbsp;filenumber&amp;nbsp;and&amp;nbsp;l%et tablename = _1&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I looking a way to do it automatically, If I have 50 files run everything 50 times for each file. I am not sure if I just need a do loop, or define a macro or maybe something else. I have also a macro that stops if an error appears in any step.&lt;/P&gt;
&lt;P&gt;Can anyone point me out who to sort this problem out?. My fingers will really appreciate it.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The files are stored with numbers basically, therefore files&amp;nbsp;are named from 1 to 50.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let odata = _gf_income; * data name for importing first time ;
%let ldata = _long_gf_income; * data name where data is transform to long format ;
%let final = _final_gf_income; * final version containing just london stock exchange companies ;
%let filenumber = 1 ;
%let tablename = _1 ;
%let all_tables = all_incomestatements;
%macro check_for_errors;
   %if &amp;amp;syserr &amp;gt; 0 %then %do;
      %abort cancel;
   %end;
%mend check_for_errors;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2019 18:58:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Execute-a-set-of-procedures-quot-X-quot-times-Each-time-change/m-p/545925#M8119</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-03-25T18:58:47Z</dc:date>
    </item>
    <item>
      <title>Re: Execute a set of procedures "X" times. Each time change to the next number (file)</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Execute-a-set-of-procedures-quot-X-quot-times-Each-time-change/m-p/545931#M8121</link>
      <description>&lt;P&gt;Here are my suggestions:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Run your SAS programs as a batch job with the ERRORABEND option then you won't need an error checking macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Write a DATA step to construct a %INCLUDE statement to read in and run your series of procedures using CALL EXECUTE. This way you can avoid macros entirely. It would look something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  do Loop_Count = 1 to 50;
    exec_stmt = '%let filenumber = ' !! put(Loop_Count, 2.) !! 
                '; %include "MySASProgramFolder\MySASProgram.sas";';
    call execute('%nrstr(' !! exec_stmt !! ')');
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 25 Mar 2019 19:13:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Execute-a-set-of-procedures-quot-X-quot-times-Each-time-change/m-p/545931#M8121</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2019-03-25T19:13:45Z</dc:date>
    </item>
  </channel>
</rss>

