<?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: macro variable as a column value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/macro-variable-as-a-column-value/m-p/688160#M209006</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;date=&amp;amp;today.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You get the incorrect results because macro variables are just text, they do not have any other meaning, and they do not have the meaning that they are actual dates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So the line of code above uses text substitution, the value of the macro variable is substituted in the place of the macro variable when SAS runs, and the line above becomes&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;date=SEP20;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which then is evaluated as DATA step code, and SAS interprets SEP20 not as a date, but as variable named SEP20 (because that's what it means in a DATA step), and tries to assign the value of variable SEP20 to DATE, but variable SEP20 doesn't exist. So SAS does what you told it to do, assign to the variable DATE the value of variable SEP20, which doesn't exist.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is why other people have advised you to use just plain old DATA step code and avoid the complications of macros here. Others in this thread have also explained how to get your macro variables to work properly. For example,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13976"&gt;@SASKiwi&lt;/a&gt;&amp;nbsp;has specifically included in his code instructions for the data step to interpret the macro variable as a SAS date value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 01 Oct 2020 11:18:39 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2020-10-01T11:18:39Z</dc:date>
    <item>
      <title>macro variable as a column value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-variable-as-a-column-value/m-p/688127#M208989</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data _null_;
call symput('today',put(intnx('month',today(),-1),MONYY.));
run;
%put &amp;amp;today.;

data test;
date=&amp;amp;today.;
run;&lt;/PRE&gt;&lt;P&gt;output:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;645  %put &amp;amp;today.;
SEP20
646
647  data test;
648  date=&amp;amp;today.;
649  run;

NOTE: Variable SEP20 is uninitialized.
NOTE: The data set WORK.TEST has 1 observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           0.05 seconds
      cpu time            0.01 seconds


NOTE: This SAS session is using a registry in WORK.  All changes will be lost at the end of this
      session.&lt;/PRE&gt;&lt;P&gt;want:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;table with one column named 'date' and value that resolves to, the macro variable above.&lt;/P&gt;&lt;P&gt;like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;date&lt;/P&gt;&lt;P&gt;SEP20&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;have for now:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 568px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/50043i37B109E69539F455/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Oct 2020 07:46:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-variable-as-a-column-value/m-p/688127#M208989</guid>
      <dc:creator>jepafob</dc:creator>
      <dc:date>2020-10-01T07:46:54Z</dc:date>
    </item>
    <item>
      <title>Re: macro variable as a column value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-variable-as-a-column-value/m-p/688128#M208990</link>
      <description>&lt;P&gt;Try this - to specify a proper SAS date variable you need to include the day, month and year:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
call symput('today',put(intnx('month',today(),-1),MONYY.));
run;
%put &amp;amp;today.;

data test;&lt;BR /&gt;format date date9.;
date="01&amp;amp;today."d;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Oct 2020 08:00:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-variable-as-a-column-value/m-p/688128#M208990</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2020-10-01T08:00:38Z</dc:date>
    </item>
    <item>
      <title>Re: macro variable as a column value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-variable-as-a-column-value/m-p/688129#M208991</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the need of using a macro-variable ? Just set your date variable directly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
format date monyy.;
date=intnx('month',today(),-1);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Oct 2020 08:11:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-variable-as-a-column-value/m-p/688129#M208991</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2020-10-01T08:11:04Z</dc:date>
    </item>
    <item>
      <title>Re: macro variable as a column value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-variable-as-a-column-value/m-p/688130#M208992</link>
      <description>&lt;P&gt;Maxim 33 and Maxim 28.&lt;/P&gt;
&lt;P&gt;Keep date values as SAS dates and use formats.&lt;/P&gt;
&lt;P&gt;Do not format macro variables, unless you need them in human-readable form (e.g. in titles or labels).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let today = %sysfunc(intnx(month,%sysfunc(today()),-1));

data test;
date = &amp;amp;today.;
format date monyy.;
run;

proc print data=test;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;Beob.	date
1	SEP20
&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Oct 2020 08:11:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-variable-as-a-column-value/m-p/688130#M208992</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-10-01T08:11:10Z</dc:date>
    </item>
    <item>
      <title>Re: macro variable as a column value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-variable-as-a-column-value/m-p/688160#M209006</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;date=&amp;amp;today.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You get the incorrect results because macro variables are just text, they do not have any other meaning, and they do not have the meaning that they are actual dates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So the line of code above uses text substitution, the value of the macro variable is substituted in the place of the macro variable when SAS runs, and the line above becomes&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;date=SEP20;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which then is evaluated as DATA step code, and SAS interprets SEP20 not as a date, but as variable named SEP20 (because that's what it means in a DATA step), and tries to assign the value of variable SEP20 to DATE, but variable SEP20 doesn't exist. So SAS does what you told it to do, assign to the variable DATE the value of variable SEP20, which doesn't exist.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is why other people have advised you to use just plain old DATA step code and avoid the complications of macros here. Others in this thread have also explained how to get your macro variables to work properly. For example,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13976"&gt;@SASKiwi&lt;/a&gt;&amp;nbsp;has specifically included in his code instructions for the data step to interpret the macro variable as a SAS date value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Oct 2020 11:18:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-variable-as-a-column-value/m-p/688160#M209006</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-10-01T11:18:39Z</dc:date>
    </item>
  </channel>
</rss>

