<?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: Converting a MMYY Macro Variable in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Converting-a-MMYY-Macro-Variable/m-p/723542#M27975</link>
    <description>&lt;P&gt;I'm pretty sure that you are getting NOV60 because your install is using a "best" informat when MMYYN4. doesn't exist. At least I get errors and can't find a reference to an MMYYN Informat.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Consider:&lt;/P&gt;
&lt;PRE&gt;124  data junk;
125     x= 0321;
126     put x= date9. x=monyy5.;
127  run;

x=17NOV1960 x=NOV60
&lt;/PRE&gt;
&lt;P&gt;So I think you are getting the input resulting in the numeric 312 and not a "date" in 2021.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Don't know why your log doesn't show the issues with the informat attempt that I do:&lt;/P&gt;
&lt;PRE&gt;100   %let FM = %sysfunc(inputn(&amp;amp;filemonth,MMYYn4.));
WARNING: Argument 2 to function INPUTN referenced by the %SYSFUNC or %QSYSFUNC macro function is
         out of range.
NOTE: Mathematical operations could not be performed during %SYSFUNC function execution. The
      result of the operations have been set to a missing value.

&lt;/PRE&gt;
&lt;P&gt;Since arguement 2 is the informat name...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you have a custom informat somewhere name MMYYN?&lt;/P&gt;</description>
    <pubDate>Thu, 04 Mar 2021 18:04:05 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-03-04T18:04:05Z</dc:date>
    <item>
      <title>Converting a MMYY Macro Variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Converting-a-MMYY-Macro-Variable/m-p/723528#M27973</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help me...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am looking for a solution to a very basic problem. I am new to SAS and don't use it too often, so get quite tied up in the formatting.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a check I'd like to do whereby I check a prompt date (&lt;EM&gt;Cut_off_date_prompt&lt;/EM&gt; is currently same as &lt;EM&gt;Cutoff_Date&lt;/EM&gt;) against another date and abort/cancel if the two are different. Forgive me if my code is terrible.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Program code is below, &lt;EM&gt;excerpt&lt;/EM&gt; of the&amp;nbsp;log below that. My prompt works fine, as does the conversion. FM variable is returning NOV60 not MAR21. I am assuming this is because it is reading this as a number, but am unsure how to convert that to a date?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;PROGRAM&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;%let Cutoff_Date = '01Mar2021'd ;&lt;BR /&gt;%put &amp;amp;Cutoff_Date;&lt;/P&gt;&lt;P&gt;%let fileyear = 2021;&lt;BR /&gt;%let filemonth = 0321;&lt;BR /&gt;%let prevfileyear = 2021;&lt;BR /&gt;%let prevfilemonth = 0221;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let CoDP = %sysfunc(inputn(&amp;amp;cutoff_date_prompt,date9.),monyy.);&lt;BR /&gt;%let FM = %sysfunc(inputn(&amp;amp;filemonth,MMYYn4.),monyy.);&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;%put &amp;amp;CoDP;&lt;BR /&gt;%put &amp;amp;FM;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;%macro datecheck;&lt;BR /&gt;%if &amp;amp;CoDP ne &amp;amp;FM %then&lt;BR /&gt;%abort cancel;&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;LOG&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;20 NOGTITLE
21 NOGFOOTNOTE
22 GPATH=&amp;amp;sasworklocation
23 ENCODING=UTF8
24 options(rolap="on")
25 ;
26
27 GOPTIONS ACCESSIBLE;
28
29 %let Cutoff_Date = '01Mar2021'd ;
30 %put &amp;amp;Cutoff_Date;
'01Mar2021'd
31
32 %let fileyear = 2021;
33 %let filemonth = 0321;
34 %let prevfileyear = 2021;
35 %let prevfilemonth = 0221;
36
37 %let CoDP = %sysfunc(inputn(&amp;amp;cutoff_date_prompt,date9.),monyy.);
38
39
40 %let FM = %sysfunc(inputn(&amp;amp;filemonth,MMYYn4.),monyy.);
41
42 %put &amp;amp;CoDP;
MAR21
43 %put &amp;amp;FM;
NOV60
44
45 %macro datecheck;
46 %if &amp;amp;CoDP ne &amp;amp;FM %then
2 The SAS System 12:21 Thursday, March 4, 2021

47 %abort cancel;
48 %mend;
49
50 %put _user_;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;Greedy&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 18:07:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Converting-a-MMYY-Macro-Variable/m-p/723528#M27973</guid>
      <dc:creator>GreedySheedy</dc:creator>
      <dc:date>2021-03-04T18:07:02Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a MMYY Macro Variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Converting-a-MMYY-Macro-Variable/m-p/723536#M27974</link>
      <description>&lt;P&gt;First, please help us out, from now on (as in 100% of the time in the future), please paste your log into the window that appears when you click on the &amp;lt;/&amp;gt; icon. This causes the log to be properly formatted and much more readable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When using macro variables, you are best off not formatting them (except in the case where you need to put them into a title or label or some other form which must be human readable). Then you don't have to go through the trouble of unformatting and/or formatting them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let Cutoff_Date = %sysevalf('01Mar2021'd) ; /* Note: not formatted */
%put &amp;amp;=Cutoff_Date;

%let fileyear = 2021;
%let filemonth = 0321;
%let prevfileyear = 2021;
%let prevfilemonth = 0221;

%let CoDP = %sysfunc(putn(&amp;amp;cutoff_date,monyy.));
%let FM = %sysfunc(inputn(01&amp;amp;filemonth,ddmmyy.),monyy.);


%put &amp;amp;=CoDP;
%put &amp;amp;=FM;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but since &amp;amp;CoDP and &amp;amp;FM don't need to be formatted to test their equality, I suggest using built-in SAS function INTNX that can determine the first day of each month, and then you can compare those to each other, without formatting. Note: I have forced FM to be the first day of the month. So now your code doesn't need formatted dates that are human readable to work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let CoDP = %sysfunc(intnx(month,&amp;amp;cutoff_date,0,b)); /* Note: Not formatted */
%let FM = %sysfunc(inputn(01&amp;amp;filemonth,ddmmyy.)); /* Note: Not formatted */

%put &amp;amp;=CoDP;
%put &amp;amp;=FM;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Lastly, you tried to you an informat MMYYN4., which doesn't exist.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 17:53:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Converting-a-MMYY-Macro-Variable/m-p/723536#M27974</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-03-04T17:53:22Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a MMYY Macro Variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Converting-a-MMYY-Macro-Variable/m-p/723542#M27975</link>
      <description>&lt;P&gt;I'm pretty sure that you are getting NOV60 because your install is using a "best" informat when MMYYN4. doesn't exist. At least I get errors and can't find a reference to an MMYYN Informat.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Consider:&lt;/P&gt;
&lt;PRE&gt;124  data junk;
125     x= 0321;
126     put x= date9. x=monyy5.;
127  run;

x=17NOV1960 x=NOV60
&lt;/PRE&gt;
&lt;P&gt;So I think you are getting the input resulting in the numeric 312 and not a "date" in 2021.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Don't know why your log doesn't show the issues with the informat attempt that I do:&lt;/P&gt;
&lt;PRE&gt;100   %let FM = %sysfunc(inputn(&amp;amp;filemonth,MMYYn4.));
WARNING: Argument 2 to function INPUTN referenced by the %SYSFUNC or %QSYSFUNC macro function is
         out of range.
NOTE: Mathematical operations could not be performed during %SYSFUNC function execution. The
      result of the operations have been set to a missing value.

&lt;/PRE&gt;
&lt;P&gt;Since arguement 2 is the informat name...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you have a custom informat somewhere name MMYYN?&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 18:04:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Converting-a-MMYY-Macro-Variable/m-p/723542#M27975</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-03-04T18:04:05Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a MMYY Macro Variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Converting-a-MMYY-Macro-Variable/m-p/723543#M27976</link>
      <description>&lt;P&gt;Just a trivial comment: You will rarely need to use a %sysevalf around a SAS time or date or datetime constant. The parser converts strings like&amp;nbsp;'01Mar2021'd to a number, so you can use it directly in the subsequent function calls.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let Cutoff_Date = '01Mar2021'd;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 18:04:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Converting-a-MMYY-Macro-Variable/m-p/723543#M27976</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2021-03-04T18:04:18Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a MMYY Macro Variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Converting-a-MMYY-Macro-Variable/m-p/723544#M27977</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let Cutoff_Date = '01Mar2021'd ;
%let prev_month = %sysfunc(intnx(month, &amp;amp;cutoff_date, -1, s));


%let fileyear = %sysfunc(putn(&amp;amp;cutoff_date, year4.));
%let filemonth = %sysfunc(putn(&amp;amp;cutoff_date, mmyyn4.));
%let prevfileyear = %sysfunc(putn(&amp;amp;prev_month, year4.));
%let prevfilemonth =  %sysfunc(putn(&amp;amp;prev_month, mmyyn4.));
%let FM =  %sysfunc(putn(&amp;amp;cutoff_date,  monyy5.));
 
 
 
 %put &amp;amp;Cutoff_Date;
 %put &amp;amp;Prev_month.;
 %PUT &amp;amp;fileYear.;
 %put &amp;amp;fileMonth.;
 %put &amp;amp;prevfileyear;
 %put &amp;amp;prevfileMonth.;
 %put &amp;amp;fm.;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Make sure to use date logic and functions. See above for an example that matches what you're trying to do but uses two dates as the starting point and then formats to customize them as needed for presentation. Note that you can create multiple variables or you can modify your code to have the %SYSFUNC() where it needs it as well.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a great, but longer and in depth, reference for dates and times in SAS&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/276125"&gt;@GreedySheedy&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please help me...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am looking for a solution to a very basic problem. I am new to SAS and don't use it too often, so get quite tied up in the formatting.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a check I'd like to do whereby I check a prompt date (&lt;EM&gt;Cut_off_date_prompt&lt;/EM&gt; is currently same as &lt;EM&gt;Cutoff_Date&lt;/EM&gt;) against another date and abort/cancel if the two are different. Forgive me if my code is terrible.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Program code is below, &lt;EM&gt;excerpt&lt;/EM&gt; of the&amp;nbsp;log below that. My prompt works fine, as does the conversion. FM variable is returning NOV60 not MAR21. I am assuming this is because it is reading this as a number, but am unsure how to convert that to a date?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;PROGRAM&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;%let Cutoff_Date = '01Mar2021'd ;&lt;BR /&gt;%put &amp;amp;Cutoff_Date;&lt;/P&gt;
&lt;P&gt;%let fileyear = 2021;&lt;BR /&gt;%let filemonth = 0321;&lt;BR /&gt;%let prevfileyear = 2021;&lt;BR /&gt;%let prevfilemonth = 0221;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let CoDP = %sysfunc(inputn(&amp;amp;cutoff_date_prompt,date9.),monyy.);&lt;BR /&gt;%let FM = %sysfunc(inputn(&amp;amp;filemonth,MMYYn4.),monyy.);&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;%put &amp;amp;CoDP;&lt;BR /&gt;%put &amp;amp;FM;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;%macro datecheck;&lt;BR /&gt;%if &amp;amp;CoDP ne &amp;amp;FM %then&lt;BR /&gt;%abort cancel;&lt;BR /&gt;%mend;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;LOG&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;20 NOGTITLE
21 NOGFOOTNOTE
22 GPATH=&amp;amp;sasworklocation
23 ENCODING=UTF8
24 options(rolap="on")
25 ;
26
27 GOPTIONS ACCESSIBLE;
28
29 %let Cutoff_Date = '01Mar2021'd ;
30 %put &amp;amp;Cutoff_Date;
'01Mar2021'd
31
32 %let fileyear = 2021;
33 %let filemonth = 0321;
34 %let prevfileyear = 2021;
35 %let prevfilemonth = 0221;
36
37 %let CoDP = %sysfunc(inputn(&amp;amp;cutoff_date_prompt,date9.),monyy.);
38
39
40 %let FM = %sysfunc(inputn(&amp;amp;filemonth,MMYYn4.),monyy.);
41
42 %put &amp;amp;CoDP;
MAR21
43 %put &amp;amp;FM;
NOV60
44
45 %macro datecheck;
46 %if &amp;amp;CoDP ne &amp;amp;FM %then
2 The SAS System 12:21 Thursday, March 4, 2021

47 %abort cancel;
48 %mend;
49
50 %put _user_;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please help!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;
&lt;P&gt;Greedy&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 18:09:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Converting-a-MMYY-Macro-Variable/m-p/723544#M27977</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-03-04T18:09:29Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a MMYY Macro Variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Converting-a-MMYY-Macro-Variable/m-p/723753#M27986</link>
      <description>&lt;P&gt;Thank you for the replies and feedback/tips, it's much appreciated.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Mar 2021 03:14:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Converting-a-MMYY-Macro-Variable/m-p/723753#M27986</guid>
      <dc:creator>GreedySheedy</dc:creator>
      <dc:date>2021-03-05T03:14:20Z</dc:date>
    </item>
  </channel>
</rss>

