<?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 Help with scheduling code to run automatically and update variable automatically? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Help-with-scheduling-code-to-run-automatically-and-update/m-p/787694#M32320</link>
    <description>&lt;P&gt;I am wondering if this is possible in SAS. I am working in enterprise and noticed that I can schedule for projects to be ran, I currently run a program once a week that only requires me to update a variable by 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to automate this if possible, how can I write code to update this variable every time it is scheduled to run? In another language like python I would write some code like this. Is there a way to do this in SAS?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;week_num = 1&lt;/P&gt;&lt;P&gt;temp_inc = 1&lt;/P&gt;&lt;P&gt;first_time_running = True&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if first_time_running = False then temp_inc = temp_inc + 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if first_time_running = True&amp;nbsp; then week_num = 1 and first_time_running = False&lt;/P&gt;&lt;P&gt;else week_num = temp_inc&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;set test_2;&lt;/P&gt;&lt;P&gt;use week_num;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 29 Dec 2021 21:54:46 GMT</pubDate>
    <dc:creator>helloagainoh2</dc:creator>
    <dc:date>2021-12-29T21:54:46Z</dc:date>
    <item>
      <title>Help with scheduling code to run automatically and update variable automatically?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Help-with-scheduling-code-to-run-automatically-and-update/m-p/787694#M32320</link>
      <description>&lt;P&gt;I am wondering if this is possible in SAS. I am working in enterprise and noticed that I can schedule for projects to be ran, I currently run a program once a week that only requires me to update a variable by 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to automate this if possible, how can I write code to update this variable every time it is scheduled to run? In another language like python I would write some code like this. Is there a way to do this in SAS?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;week_num = 1&lt;/P&gt;&lt;P&gt;temp_inc = 1&lt;/P&gt;&lt;P&gt;first_time_running = True&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if first_time_running = False then temp_inc = temp_inc + 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if first_time_running = True&amp;nbsp; then week_num = 1 and first_time_running = False&lt;/P&gt;&lt;P&gt;else week_num = temp_inc&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;set test_2;&lt;/P&gt;&lt;P&gt;use week_num;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Dec 2021 21:54:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Help-with-scheduling-code-to-run-automatically-and-update/m-p/787694#M32320</guid>
      <dc:creator>helloagainoh2</dc:creator>
      <dc:date>2021-12-29T21:54:46Z</dc:date>
    </item>
    <item>
      <title>Re: Help with scheduling code to run automatically and update variable automatically?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Help-with-scheduling-code-to-run-automatically-and-update/m-p/787697#M32321</link>
      <description>&lt;P&gt;I would create a permanent SAS data set (which I will name mylib.dsname) with only one variable (let's call it BOB) and only one observation. The first time you run it, the data set is created and BOB gets the value of 1. Then next time you run it, BOB has the value of 2, and so on.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname mylib "somevalidlocation";
%if %sysfunc(exist(mylib.dsname)) %then %do;
data mylib.dsname;
    set mylib.dsname;
    bob=bob+1;
run;
%end;
%else %do;
data mylib.dsname;
    bob=1;
run;
%end;
  &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note: works in SAS 9.4M5 or later.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Dec 2021 22:27:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Help-with-scheduling-code-to-run-automatically-and-update/m-p/787697#M32321</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-12-29T22:27:17Z</dc:date>
    </item>
    <item>
      <title>Re: Help with scheduling code to run automatically and update variable automatically?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Help-with-scheduling-code-to-run-automatically-and-update/m-p/787698#M32322</link>
      <description>Where do you store your data?&lt;BR /&gt;In that location, create a table with the iteration run. When you finish a run, update that table so that there's a new record. At the start of the process you would read that record to get the newest value to work with. &lt;BR /&gt;&lt;BR /&gt;Untested general idea, assuming you also understand the concept of macro variables. &lt;BR /&gt;&lt;BR /&gt;*start of process;&lt;BR /&gt;proc sql noprint;&lt;BR /&gt;select max(iteration)+1 into :next_iter from iteration_count;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;/*process uses &amp;amp;next_iter value*/&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;/*end of process*;&lt;BR /&gt;proc sq;&lt;BR /&gt;insert into iteration_count&lt;BR /&gt;select &amp;amp;max_iter +1;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;And just as an FYI - if this iteration revolves around dates then there are better ways to do this.</description>
      <pubDate>Wed, 29 Dec 2021 22:29:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Help-with-scheduling-code-to-run-automatically-and-update/m-p/787698#M32322</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-12-29T22:29:18Z</dc:date>
    </item>
    <item>
      <title>Re: Help with scheduling code to run automatically and update variable automatically?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Help-with-scheduling-code-to-run-automatically-and-update/m-p/787710#M32323</link>
      <description>&lt;P&gt;If you just need some indication in which week you've executed a job then why not just store the execution date as a SAS date value. This would avoid the need to maintain some permanent table for maintaining some execution counter ...and the additional logic required to not increase this counter when re-running in the same week because something went wrong the first time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you just store the date as a SAS Date value then you can always use SAS functions like intck() or week() to derive week counts.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below some sample code showing options.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let first_run_dt='1jan2020'd;
data test;
  set sashelp.class;
  week_num_1=intck('week',&amp;amp;first_run_dt,today());
  week_num_2=week(today());
  yyww_num=input(cats(year(today()),put(week(today()),z2.)),16.);
  dt=today();
  format dt weekv.;
run;&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-1640835961777.png" style="width: 652px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66996iF244615A9AC6AE1E/image-dimensions/652x85?v=v2" width="652" height="85" role="button" title="Patrick_0-1640835961777.png" alt="Patrick_0-1640835961777.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Dec 2021 03:46:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Help-with-scheduling-code-to-run-automatically-and-update/m-p/787710#M32323</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-12-30T03:46:16Z</dc:date>
    </item>
  </channel>
</rss>

