<?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: Automatically save SAS program with current date in code in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Automatically-save-SAS-program-with-current-date-in-code/m-p/806004#M317520</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/353537"&gt;@bananah13&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For a really production worthy version of what you're doing you would use a scheduler to run your code in batch.&lt;/P&gt;
&lt;P&gt;Others already commented how to manage code changes and that this requires a version control tool if done seriously.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now... IF you want to store the SAS code executed at a specific point in time after all SAS macro logic and macro variables have been resolved then you could use and approach like below.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro wrapper();
  /** here your current program */

  %let month_key=%sysfunc(intnx(month,%sysfunc(date()),0,b),yymmn6.);
  data test_&amp;amp;month_key;
    set sashelp.class;
  run;

  /** here the end of your current program **/
%mend;

/** this bit new to execute the macro and capture the generated SAS code **/
filename mprint "c:\temp\myprog_run_%sysfunc(datetime(),B8601DT.).sas";
options mprint mfile;
%wrapper();
options nomfile;
/*filename mprint clear;*/
/** end of new code section **/

/** this bit just for the question here to print the generated code **/
data _null_;
  file print;
  infile mprint;
  input;
  put _infile_;
run;
filename mprint clear;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1649150527519.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/70119i8ABE868B41E7FF84/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1649150527519.png" alt="Patrick_0-1649150527519.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;You basically wrap a SAS macro around all of your code and then store the generated SAS code by this macro in an external file with a datestamp.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Above is NOT a replacement for version control but a way to collect generated SAS code in a way that's easier to read (and re-execute) than what you get in the SAS log.&lt;/P&gt;</description>
    <pubDate>Tue, 05 Apr 2022 09:24:05 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2022-04-05T09:24:05Z</dc:date>
    <item>
      <title>Automatically save SAS program with current date in code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automatically-save-SAS-program-with-current-date-in-code/m-p/805922#M317490</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have a SQL to SAS program that must be run monthly. I recently used EG to automate the process at the beginning of each month so I don't have to remember to go in and manually run it each month, which is working great.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Part of the QC process for the monthly run is to save the SAS program with the run date (to keep track of any program changes). Is there code I could put in my program that would automatically save it? I tried to proc export the .sas program, but it looks like you can only export datasets. Ideas?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Apr 2022 19:42:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automatically-save-SAS-program-with-current-date-in-code/m-p/805922#M317490</guid>
      <dc:creator>bananah13</dc:creator>
      <dc:date>2022-04-04T19:42:31Z</dc:date>
    </item>
    <item>
      <title>Re: Automatically save SAS program with current date in code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automatically-save-SAS-program-with-current-date-in-code/m-p/805928#M317495</link>
      <description>&lt;P&gt;Keeping track of program changes is best done with a versioning tool rather than doing it yourself manually. EG supports the use of GIT for version control.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can find out more here:&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/egdoccdc/8.2/egug/p078cl08fol7hkn11a8nf1f9izq7.htm" target="_blank"&gt;SAS Help Center: About Git Integration in SAS Enterprise Guide&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Apr 2022 20:02:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automatically-save-SAS-program-with-current-date-in-code/m-p/805928#M317495</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-04-04T20:02:59Z</dc:date>
    </item>
    <item>
      <title>Re: Automatically save SAS program with current date in code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automatically-save-SAS-program-with-current-date-in-code/m-p/805990#M317516</link>
      <description>&lt;P&gt;Tracking of&amp;nbsp;&lt;EM&gt;code&lt;/EM&gt; has to be done in a proper code management tool, like git or svn or (insert gazillion of others).&lt;/P&gt;
&lt;P&gt;To keep a documentation of how data was built, keep the&amp;nbsp;&lt;EM&gt;logs&lt;/EM&gt;. Make sure that the runtime is included properly in the logfile name (YYYYMMDDHHMMSS), so that each run gets its own log.&lt;/P&gt;
&lt;P&gt;Proper automation of code needs to be done server-side, not from EG. Save your whole code as a .sas file to the server, and set up batch execution of the code there. Depending on your needs, crontab may suffice, but using a dedicated scheduling tool is preferred, especially if your company/organization already has one.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Apr 2022 07:21:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automatically-save-SAS-program-with-current-date-in-code/m-p/805990#M317516</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-05T07:21:05Z</dc:date>
    </item>
    <item>
      <title>Re: Automatically save SAS program with current date in code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automatically-save-SAS-program-with-current-date-in-code/m-p/806004#M317520</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/353537"&gt;@bananah13&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For a really production worthy version of what you're doing you would use a scheduler to run your code in batch.&lt;/P&gt;
&lt;P&gt;Others already commented how to manage code changes and that this requires a version control tool if done seriously.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now... IF you want to store the SAS code executed at a specific point in time after all SAS macro logic and macro variables have been resolved then you could use and approach like below.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro wrapper();
  /** here your current program */

  %let month_key=%sysfunc(intnx(month,%sysfunc(date()),0,b),yymmn6.);
  data test_&amp;amp;month_key;
    set sashelp.class;
  run;

  /** here the end of your current program **/
%mend;

/** this bit new to execute the macro and capture the generated SAS code **/
filename mprint "c:\temp\myprog_run_%sysfunc(datetime(),B8601DT.).sas";
options mprint mfile;
%wrapper();
options nomfile;
/*filename mprint clear;*/
/** end of new code section **/

/** this bit just for the question here to print the generated code **/
data _null_;
  file print;
  infile mprint;
  input;
  put _infile_;
run;
filename mprint clear;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1649150527519.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/70119i8ABE868B41E7FF84/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1649150527519.png" alt="Patrick_0-1649150527519.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;You basically wrap a SAS macro around all of your code and then store the generated SAS code by this macro in an external file with a datestamp.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Above is NOT a replacement for version control but a way to collect generated SAS code in a way that's easier to read (and re-execute) than what you get in the SAS log.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Apr 2022 09:24:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automatically-save-SAS-program-with-current-date-in-code/m-p/806004#M317520</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-04-05T09:24:05Z</dc:date>
    </item>
  </channel>
</rss>

