<?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: Creating a Macro Variable, but format is incorrect. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-Macro-Variable-but-format-is-incorrect/m-p/740360#M231262</link>
    <description>&lt;P&gt;yeah, it's not really an error but a warning.&lt;/P&gt;&lt;P&gt;I have some other codes after that call up this variable to search our folder to see if xxxx_202104 file would exist.&lt;/P&gt;&lt;P&gt;That's where the error comes.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 11 May 2021 03:48:56 GMT</pubDate>
    <dc:creator>tonywu</dc:creator>
    <dc:date>2021-05-11T03:48:56Z</dc:date>
    <item>
      <title>Creating a Macro Variable, but format is incorrect.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-Macro-Variable-but-format-is-incorrect/m-p/740334#M231249</link>
      <description>&lt;P&gt;Hi community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have come across following error when I was trying to create a macro variable.&lt;/P&gt;&lt;P&gt;Hope you guys could help in this case.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We are currently using MONTH_1 where we need to change the input each month.&lt;/P&gt;&lt;P&gt;So I tried to create MONTH so that it will automatically run last month data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However the problem is that MONTH_1 is character, MONTH will be numeric.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried &amp;lt;&amp;lt;&amp;lt;%let MONTH = %sysfunc(put(%sysfunc(intnx(month, %sysfunc(today()), -3), yymmn6.), $.);&amp;gt;&amp;gt;&amp;gt;, but still getting the warning that "VARIABLE HAS ALREADY BEEN DEFINED AS NUMERIC".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks and regards,&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Macro Variables*/
%let MONTH_1 = '202104';
%let MONTH = %sysfunc(intnx(month, %sysfunc(today()), -3), yymmn6.);
/*%let NOW = %sysfunc(today(), yymmn6.);*/

data _null_;
call symput('BEG_DATE',put(intnx('month',input(put(&amp;amp;MONTH.,$6.), yymmn6.),-12,'b'),yymmn6.));
call symput('RCMS_DATE',put(intnx('month',input(put(&amp;amp;MONTH.,$6.), yymmn6.),-13,'b'),yymmn6.));
call symput('EXTRACT',put(intnx('month',input(put(&amp;amp;MONTH.,$6.), yymmn6.),0,'e'),yymmn6.));
call symput('EXT_DATE',put(intnx('month',input(put(&amp;amp;MONTH.,$6.), yymmn6.),0,'e'),date9.));
call symput('TAB_DATE',put(intnx('month',input(put(&amp;amp;MONTH.,$6.), yymmn6.),-84,'b'),yymmn6.));
call symput('LAST_PERF_DATE',put(intnx('month',input(put(&amp;amp;MONTH.,$6.), yymmn6.),-18,'e'),date9.)); *Allowing 18 mths outcome window;
call symput('LAST_PERF_MTH',put(intnx('month',input(put(&amp;amp;MONTH.,$6.), yymmn6.),-18,'e'),yymmn6.)); *Allowing 18 mths outcome window;
run;
%put &amp;amp;BEG_DATE. &amp;amp;RCMS_DATE. &amp;amp;EXTRACT. &amp;amp;EXT_DATE. &amp;amp;TAB_DATE. &amp;amp;LAST_PERF_DATE. &amp;amp;LAST_PERF_MTH. &amp;amp;MONTH &amp;amp;MONTH_1;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 May 2021 00:45:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-Macro-Variable-but-format-is-incorrect/m-p/740334#M231249</guid>
      <dc:creator>tonywu</dc:creator>
      <dc:date>2021-05-11T00:45:04Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a Macro Variable, but format is incorrect.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-Macro-Variable-but-format-is-incorrect/m-p/740351#M231255</link>
      <description>&lt;P&gt;Where is the error message?&amp;nbsp; Show the SAS log lines for the data step that is generating the error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Macro variables contain text.&amp;nbsp; So this code&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let MONTH = %sysfunc(intnx(month, %sysfunc(today()), -3), yymmn6.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;will set MONTH to a string of digits that is 6 characters long.&amp;nbsp; Like 202101.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you use it to generate SAS code like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;newvar= &amp;amp;month ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then NEWVAR will be a numeric variable since you ran this statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;newvar = 202101 ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which will set NEWVAR to the number 202,101.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you set MONTH_1 to string of digits enclosed in quotes.&amp;nbsp; So if you coded&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;newvar = &amp;amp;month_1 ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then NEWVAR will be a character variable since you ran this code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;newvar = '202104' ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 May 2021 02:57:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-Macro-Variable-but-format-is-incorrect/m-p/740351#M231255</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-05-11T02:57:21Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a Macro Variable, but format is incorrect.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-Macro-Variable-but-format-is-incorrect/m-p/740355#M231259</link>
      <description>&lt;P&gt;In your data _null_ step you expect macro variable &amp;amp;month to resolve to a string of digits which you then convert to a numerical SAS date value using the input function. Because it's a string you need to have &amp;amp;month in double quotes.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Macro Variables*/
%let MONTH_1 = '202104';
%let MONTH = %sysfunc(intnx(month, %sysfunc(today()), -3), yymmn6.);

/*%let NOW = %sysfunc(today(), yymmn6.);*/
data _null_;
  call symput('BEG_DATE',put(intnx('month',input(put("&amp;amp;MONTH.",$6.), yymmn6.),-12,'b'),yymmn6.));
  call symput('RCMS_DATE',put(intnx('month',input(put("&amp;amp;MONTH.",$6.), yymmn6.),-13,'b'),yymmn6.));
  call symput('EXTRACT',put(intnx('month',input(put("&amp;amp;MONTH.",$6.), yymmn6.),0,'e'),yymmn6.));
  call symput('EXT_DATE',put(intnx('month',input(put("&amp;amp;MONTH.",$6.), yymmn6.),0,'e'),date9.));
  call symput('TAB_DATE',put(intnx('month',input(put("&amp;amp;MONTH.",$6.), yymmn6.),-84,'b'),yymmn6.));
  call symput('LAST_PERF_DATE',put(intnx('month',input(put("&amp;amp;MONTH.",$6.), yymmn6.),-18,'e'),date9.));
  *Allowing 18 mths outcome window;
  call symput('LAST_PERF_MTH',put(intnx('month',input(put("&amp;amp;MONTH.",$6.), yymmn6.),-18,'e'),yymmn6.));
  *Allowing 18 mths outcome window;
run;

%put &amp;amp;=BEG_DATE.;
%put &amp;amp;=RCMS_DATE.;
%put &amp;amp;=EXTRACT.;
%put &amp;amp;=EXT_DATE.;
%put &amp;amp;=TAB_DATE.;
%put &amp;amp;=LAST_PERF_DATE.;
%put &amp;amp;=LAST_PERF_MTH.;
%put &amp;amp;=MONTH.;
%put &amp;amp;=MONTH_1.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 May 2021 03:03:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-Macro-Variable-but-format-is-incorrect/m-p/740355#M231259</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-05-11T03:03:23Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a Macro Variable, but format is incorrect.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-Macro-Variable-but-format-is-incorrect/m-p/740357#M231260</link>
      <description>&lt;P&gt;If you want to replicate what you did before just add the quotes:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let MONTH = '202104';
%let MONTH = "%sysfunc(intnx(month, %sysfunc(today()), -3), yymmn6.)";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It is probably worth it to cut down on the number of nested function calls to make your code easier to decipher.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%let MONTH = "%sysfunc(intnx(month, %sysfunc(today()), -3), yymmn6.)";
data _null_;
*  Convert macro variable into date ;
  month = input(&amp;amp;month,yymmn6.);
  * 1 year ;
  BEG_DATE = intnx('month',month,-12);
  * 13 months ;
  RCMS_DATE = intnx('month',month,-13);
  * end of month ;
  EXT_DATE= intnx('month',month,0,'e');
  * 7 years ;
  TAB_DATE= intnx('month',month,-84);
  * 18 months ;
  LAST_PERF_DATE = intnx('month',month,-18,'e');

* Generate macro variables ;
  call symputx('BEG_DATE',put(BEG_DATE,yymmn6.));
  call symputx('RCMS_DATE',put(RCMS_DATE,yymmn6.));

  call symputx('EXTRACT',put(EXT_DATE,yymmn6.));
  call symputx('EXT_DATE',put(EXT_DATE,date9.));

  call symputx('TAB_DATE',put(TAB_DATE,yymmn6.));

  call symputx('LAST_PERF_DATE',put(LAST_PERF_DATE,date9.)); 
  call symputx('LAST_PERF_MTH',put(LAST_PERF_DATE,yymmn6.)); 
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;182   %put &amp;amp;=MONTH ;
MONTH="202102"
183   %put &amp;amp;=BEG_DATE. &amp;amp;=RCMS_DATE. &amp;amp;=EXTRACT.;
BEG_DATE=202002 RCMS_DATE=202001 EXTRACT=202102
184   %put &amp;amp;=EXT_DATE. &amp;amp;=TAB_DATE. &amp;amp;=LAST_PERF_DATE. &amp;amp;=LAST_PERF_MTH.;
EXT_DATE=28FEB2021 TAB_DATE=201402 LAST_PERF_DATE=31AUG2019 LAST_PERF_MTH=201908
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 May 2021 03:31:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-Macro-Variable-but-format-is-incorrect/m-p/740357#M231260</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-05-11T03:31:37Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a Macro Variable, but format is incorrect.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-Macro-Variable-but-format-is-incorrect/m-p/740360#M231262</link>
      <description>&lt;P&gt;yeah, it's not really an error but a warning.&lt;/P&gt;&lt;P&gt;I have some other codes after that call up this variable to search our folder to see if xxxx_202104 file would exist.&lt;/P&gt;&lt;P&gt;That's where the error comes.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 May 2021 03:48:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-Macro-Variable-but-format-is-incorrect/m-p/740360#M231262</guid>
      <dc:creator>tonywu</dc:creator>
      <dc:date>2021-05-11T03:48:56Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a Macro Variable, but format is incorrect.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-Macro-Variable-but-format-is-incorrect/m-p/740362#M231263</link>
      <description>&lt;P&gt;this one actually worked.&amp;nbsp;&lt;/P&gt;&lt;P&gt;it is showing the date in double quotations, where the previous one is in single quotation.&lt;/P&gt;&lt;P&gt;But I assume this would work for the following codes?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="tonywu_0-1620704970079.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/59200i85CD82469E6803A7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="tonywu_0-1620704970079.png" alt="tonywu_0-1620704970079.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 May 2021 03:50:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-Macro-Variable-but-format-is-incorrect/m-p/740362#M231263</guid>
      <dc:creator>tonywu</dc:creator>
      <dc:date>2021-05-11T03:50:02Z</dc:date>
    </item>
  </channel>
</rss>

