<?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: read in DS variable in macro var in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/read-in-DS-variable-in-macro-var/m-p/269985#M53562</link>
    <description>&lt;P&gt;Why not use WEEKDAY interval ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="sasSource"&gt;52 data _null_;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;53 havevar = '12may2016';&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;54 havevar_sas = input(trim(havevar),date9.);&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;55 havevar_sas = intnx('weekday',havevar_sas,-1);&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;56 put havevar_sas= ;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;57 run;&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;havevar_sas=20585&lt;/DIV&gt;</description>
    <pubDate>Thu, 12 May 2016 07:22:34 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2016-05-12T07:22:34Z</dc:date>
    <item>
      <title>read in DS variable in macro var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/read-in-DS-variable-in-macro-var/m-p/269973#M53558</link>
      <description>&lt;P&gt;Hello community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope you can give me some advice regarding a programming issue. My goal is to find the &lt;STRONG&gt;fore&lt;/STRONG&gt;last workday in a month. I assume, that every Monday till Friday is a workday and do not care about feast day. In the macro var load_day is the last workday of the month given.&lt;/P&gt;&lt;P&gt;Ah...I'm working with EG 7.12 HF1 which is SAS 9.4 M2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the code I have this far:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* calculate the last workday before the given load_day */
options mlogic mprint symbolgen minoperator;


%global flwd;
%let flwd = ;
%put FLWD: &amp;amp;flwd;
 
%macro forelastwd;
     data _null_;
          length havevar $9 havevar_sas 8;
          havevar = symget('load_day');
          havevar_sas = input(trim(havevar),date9.);

          do until (weekday(havevar_sas) in (2,3,4,5,6) );
                havevar_sas = intnx('day',havevar_sas,-1);
                call symput('flwd',havevar_sas);
                %put Vorletzter Werktag: &amp;amp;flwd;
          end;
     run;
%mend;
%forelastwd;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;At the end &amp;amp;flwd is assigned NULL. How do i get this to work?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Noki&lt;/P&gt;</description>
      <pubDate>Thu, 12 May 2016 06:13:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/read-in-DS-variable-in-macro-var/m-p/269973#M53558</guid>
      <dc:creator>Noki</dc:creator>
      <dc:date>2016-05-12T06:13:38Z</dc:date>
    </item>
    <item>
      <title>Re: read in DS variable in macro var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/read-in-DS-variable-in-macro-var/m-p/269974#M53559</link>
      <description>&lt;P&gt;When you place your %put within the data step, it is executed by the macro engine &lt;U&gt;before&lt;/U&gt; the data step runs. (typical macro language behaviour!)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
length havevar $9 havevar_sas 8;
*havevar = symget('load_day');
havevar = '12may2016';
havevar_sas = input(trim(havevar),date9.);
do until (weekday(havevar_sas) in (2,3,4,5,6) );
  havevar_sas = intnx('day',havevar_sas,-1);
  call symput('flwd',havevar_sas);
end;
run;
%put Vorletzter Werktag: &amp;amp;flwd;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;will give you this in the log:&lt;/P&gt;
&lt;PRE&gt;16         data _null_;
17         length havevar $9 havevar_sas 8;
18         *havevar = symget('load_day');
19         havevar = '12may2016';
20         havevar_sas = input(trim(havevar),date9.);
21         do until (weekday(havevar_sas) in (2,3,4,5,6) );
22           havevar_sas = intnx('day',havevar_sas,-1);
23           call symput('flwd',havevar_sas);
24         end;
25         run;

NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
      23:22   
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

26         %put Vorletzter Werktag: &amp;amp;flwd;
Vorletzter Werktag:        20585
&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 May 2016 06:27:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/read-in-DS-variable-in-macro-var/m-p/269974#M53559</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-05-12T06:27:14Z</dc:date>
    </item>
    <item>
      <title>Re: read in DS variable in macro var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/read-in-DS-variable-in-macro-var/m-p/269978#M53560</link>
      <description>Thanks a lot!&lt;BR /&gt;So programming was right, but the place was wrong.&lt;BR /&gt;You saved my day &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Thu, 12 May 2016 06:48:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/read-in-DS-variable-in-macro-var/m-p/269978#M53560</guid>
      <dc:creator>Noki</dc:creator>
      <dc:date>2016-05-12T06:48:59Z</dc:date>
    </item>
    <item>
      <title>Re: read in DS variable in macro var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/read-in-DS-variable-in-macro-var/m-p/269985#M53562</link>
      <description>&lt;P&gt;Why not use WEEKDAY interval ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="sasSource"&gt;52 data _null_;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;53 havevar = '12may2016';&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;54 havevar_sas = input(trim(havevar),date9.);&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;55 havevar_sas = intnx('weekday',havevar_sas,-1);&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;56 put havevar_sas= ;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;57 run;&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;havevar_sas=20585&lt;/DIV&gt;</description>
      <pubDate>Thu, 12 May 2016 07:22:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/read-in-DS-variable-in-macro-var/m-p/269985#M53562</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-05-12T07:22:34Z</dc:date>
    </item>
    <item>
      <title>Re: read in DS variable in macro var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/read-in-DS-variable-in-macro-var/m-p/269997#M53565</link>
      <description>&lt;P&gt;Whilst you have an answer to your problem, I would like to put some points in. &amp;nbsp;I don't see any reason given here why load_day should be a macro variable - it is numeric date data so text based macro variable is not a good storage medium for that data, or why this code given here is put in a macro at all. &amp;nbsp;Macro language is a method for generating Base SAS code, it doesn nothing else. &amp;nbsp;Base SAS code is there to process and manipulate data. &amp;nbsp;All that happens when Base SAS code is forced into Macro language is that the code becomes obfuscated. &amp;nbsp;Take your problem for instance, it is a simple task of checking if the week day of a date is a weekend, and if so returning Friday, otherwise the day. &amp;nbsp;You have compounded this simple problem by first putting a date into a text macro variable - thus you need additional code to process that back into a usable format. &amp;nbsp;Now look at the equivalent statement if your date is stored in a dataset in a strcuture which is designed to handle "data" elements:&lt;/P&gt;
&lt;PRE&gt;data have;
  load_day="12May2016"d;
  last=ifn(weekday(load_day) in (1,7),6,weekday(load_day)-1);
run;&lt;/PRE&gt;
&lt;P&gt;Simpler, doesn't require working out what is being done. &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 May 2016 08:46:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/read-in-DS-variable-in-macro-var/m-p/269997#M53565</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-05-12T08:46:25Z</dc:date>
    </item>
  </channel>
</rss>

