<?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: obtaining Month, Year combinations based on a Date prompt input in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/obtaining-Month-Year-combinations-based-on-a-Date-prompt-input/m-p/826862#M41211</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/428921"&gt;@madara155&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Following line is giving the Selected_month_no as a single digit no (for July it is giving 7 instead of 07).&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;%let&lt;/FONT&gt; Selected_month_no =&lt;FONT color="#0000FF"&gt;%sysfunc&lt;/FONT&gt;(putn(&amp;amp;userdatevalue,month2.));&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Any thoughts on how to get it as a two digit value? I tried using z2. but I think I did it incorrectly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks again&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Please show what you did when you "tried using Z2.".&lt;/P&gt;</description>
    <pubDate>Wed, 03 Aug 2022 13:26:06 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2022-08-03T13:26:06Z</dc:date>
    <item>
      <title>obtaining Month, Year combinations based on a Date prompt input</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/obtaining-Month-Year-combinations-based-on-a-Date-prompt-input/m-p/826763#M41198</link>
      <description>&lt;P&gt;I am using a Date Prompt to get a user input month in SAS. I get the input in the following format:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;STRONG&gt;UserSelectedMonth = DDMMMYYYY&lt;/STRONG&gt; (eg: 01JUL2022) – This is the macro variable obtained from prompt.&lt;/LI&gt;&lt;LI&gt;UserSelectedMonth in the MMM-YY format&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;Selected_month = JUL-22&lt;/STRONG&gt; – This must be a macro variable&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;From the UserSelectedMonth, I want to find the number corresponding to the month&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;Selected_month_no = 7&lt;/STRONG&gt; (eg: July is the 7th month) ---- This must be a macro variable&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;Extract the three-letter name of the above UserSelectedMonth&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;Selected_month_name = JUL&lt;/STRONG&gt; ---- This must be a macro variable&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;Find the year from the UserSelectedMonth as a two-digit number&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;Selected_year = 22&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ---- This must be a macro variable&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;Find the same month in 2019 in the MMMYY format&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;Month_year_19 = JUL19&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ---- This must be a macro variable&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;Previous month in the MMMYY or MMMYYYY format&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;Previous_month = JUN22&lt;/STRONG&gt; or&amp;nbsp; &lt;STRONG&gt;Previous_month = JUN2022&lt;/STRONG&gt;&amp;nbsp;&amp;nbsp; ---- This must be a macro variable&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;I need to read some automatically generated files having different file name formats, so based on the user input I need all these variables to dynamically define the files names and read them inside a program.&lt;/P&gt;&lt;P&gt;Can someone please help me to obtain the above?&lt;/P&gt;&lt;P&gt;I tried and my code does not work&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":frowning_face:"&gt;☹️&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Sorry for the long post.&lt;/P&gt;&lt;P&gt;Thanks for anyone giving some help!&lt;/P&gt;&lt;P&gt;======================================================================================================================&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;My code:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366FF"&gt;&lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; &lt;/FONT&gt;_null_&lt;/FONT&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966"&gt;/* UserSelectedMonth&amp;nbsp; is obtained from the Date prompt as a macro variable, but I just stated here so that that the rest of the code can be tested*/&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366FF"&gt;%let&lt;/FONT&gt; UserSelectedMonth&amp;nbsp; = 01JUL2022;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966"&gt;/*Try to obtain the Selected_month_no as a two digit no using the z2. format*/&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366FF"&gt;%let&lt;/FONT&gt; Selected_month_no&amp;nbsp; = &lt;FONT color="#3366FF"&gt;%sysfunc&lt;/FONT&gt;(month("&amp;amp;UserSelectedMonth."d), z2.);&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966"&gt;/*Try to obtain the Selected_month_name in three letters using the monname3. format*/&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366FF"&gt;%let&lt;/FONT&gt; Selected_month_name&amp;nbsp; = &lt;FONT color="#3366FF"&gt;%sysfunc&lt;/FONT&gt;(month("&amp;amp;UserSelectedMonth."d), monname3.);&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966"&gt;/*Extract the last two digits (Selected_year) using substr from DDMMMYYYY*/&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366FF"&gt;%let&lt;/FONT&gt; Selected_year&amp;nbsp; = &lt;FONT color="#3366FF"&gt;%sysfunc&lt;/FONT&gt;(substr("&amp;amp;UserSelectedMonth",8,2));&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966"&gt;/*Obtain Month_year_19 by combining Selected_month_name and 19*/&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366FF"&gt;%let&lt;/FONT&gt; Month_year_19&amp;nbsp; = &lt;FONT color="#3366FF"&gt;%sysfunc&lt;/FONT&gt;(cat(&amp;amp;Selected_month_name,19));&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966"&gt;/*Obtain Selected_month by combining Selected_month_name, "-" and Selected_year */&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366FF"&gt;%let&lt;/FONT&gt; Selected_month =&lt;FONT color="#3366FF"&gt;%sysfunc&lt;/FONT&gt;(cat(&amp;amp;Selected_month_name,-,&amp;amp;Selected_year));&lt;/P&gt;&lt;P&gt;&lt;FONT color="#339966"&gt;/*Obtain previous month from */&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;Previous_month&amp;nbsp; = intnx('MONTH', &lt;STRONG&gt;"&amp;amp;UserSelectedMonth"d&lt;/STRONG&gt;, -&lt;STRONG&gt;1&lt;/STRONG&gt;, 'BEGINNING');&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366FF"&gt;format&amp;nbsp;&lt;/FONT&gt; Previous_month&amp;nbsp; date9.;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366FF"&gt;call&lt;/FONT&gt; symputx('Previous_month ',&amp;nbsp; put(Previous_month ,date9.));&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366FF"&gt;%put&lt;/FONT&gt; _user_;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;;&lt;/P&gt;&lt;P&gt;=======================================================================&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Macro variables I am getting:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;GLOBAL MONTH_NAME Jan&lt;/P&gt;&lt;P&gt;GLOBAL MONTH_NO &lt;STRONG&gt;07&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;GLOBAL MONTH_YEAR_19 Jan19&lt;/P&gt;&lt;P&gt;GLOBAL SELECTEDMONTH &lt;STRONG&gt;01&lt;/STRONG&gt;Jul2022&lt;/P&gt;&lt;P&gt;GLOBAL SELECTEDMONTH_END &lt;STRONG&gt;31&lt;/STRONG&gt;Jul2022&lt;/P&gt;&lt;P&gt;GLOBAL SELECTEDMONTH_LABEL Previous month&lt;/P&gt;&lt;P&gt;GLOBAL SELECTEDMONTH_REL M-&lt;STRONG&gt;1&lt;/STRONG&gt;M&lt;/P&gt;&lt;P&gt;GLOBAL SELECTED_MONTH Jan-&lt;STRONG&gt;2&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;GLOBAL SELECTED_MONTH_NAME Jan&lt;/P&gt;&lt;P&gt;GLOBAL SELECTED_MONTH_NO &lt;STRONG&gt;07&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;GLOBAL SELECTED_YEAR &lt;STRONG&gt;02&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Aug 2022 02:02:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/obtaining-Month-Year-combinations-based-on-a-Date-prompt-input/m-p/826763#M41198</guid>
      <dc:creator>madara155</dc:creator>
      <dc:date>2022-08-03T02:02:01Z</dc:date>
    </item>
    <item>
      <title>Re: obtaining Month, Year combinations based on a Date prompt input</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/obtaining-Month-Year-combinations-based-on-a-Date-prompt-input/m-p/826771#M41199</link>
      <description>&lt;P&gt;A couple of observations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;You don't need to use the data step.&amp;nbsp; But if you do, issue the %PUT _USER_; statement &lt;EM&gt;&lt;STRONG&gt;after&lt;/STRONG&gt;&lt;/EM&gt; the run; statement.&lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;
&lt;LI&gt;Instead of repeated use of "&amp;amp;userselectedmonth"d, make a USERDATEVALUE=%sysevalf("&amp;amp;userselectedmonth"d); and then use that macrovar as the primary date source.&lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;
&lt;LI&gt;Consider your statement&amp;nbsp; &amp;nbsp;&amp;nbsp;
&lt;P&gt;&lt;FONT color="#3366FF"&gt;%let&lt;/FONT&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;Selected_month_name&amp;nbsp; =&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT color="#3366FF"&gt;%sysfunc&lt;/FONT&gt;(month("&amp;amp;UserSelectedMonth."d), monname3.);&lt;BR /&gt;It does the following&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Gets the month number of UserselectedMonth = 7&lt;/LI&gt;
&lt;LI&gt;Applies the monname3. format to the value of 7.&amp;nbsp; But because the monname3. format is &lt;EM&gt;&lt;STRONG&gt;intended for date values,&lt;/STRONG&gt;&lt;/EM&gt; it treats the 7 as representing 08jan1960&amp;nbsp; (date values use zero for 01jan1960).&amp;nbsp; Since the month for date=7 is January, you will get JAN, even though you intended to get JUL.&lt;/LI&gt;
&lt;/OL&gt;
&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Here are suggested replacements:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let UserSelectedMonth=01jul2022;
%let userdatevalue=%sysevalf("&amp;amp;UserSelectedMonth"d);

%let Selected_month_no   =%sysfunc(putn(&amp;amp;userdatevalue,month2.));
%let Selected_month_name =%sysfunc(putn(&amp;amp;userdatevalue,monname3.));
%let Selected_year       =%sysfunc(putn(&amp;amp;Userdatevalue,year2.));
%let month_year_19       =&amp;amp;selected_month_name.19;
%let previous_month      =%sysfunc(intnx(month,&amp;amp;userdatevalue,-1),monyy7.);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The primary points here are:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;You can use the %SYSEVALF macro function to evaluate a date literal, as above.&amp;nbsp; As you can see, I use that underlying value in the subsequent &lt;EM&gt;&lt;STRONG&gt;%SYSFUNC(putn( ....&lt;/STRONG&gt;&lt;/EM&gt; expressions.&lt;/LI&gt;
&lt;LI&gt;Just as you can apply formats to the PUT function in a DATA step, you can use the PUTN function with formats embedded in a %SYSFUNC macro function.&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Wed, 03 Aug 2022 12:23:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/obtaining-Month-Year-combinations-based-on-a-Date-prompt-input/m-p/826771#M41199</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-08-03T12:23:20Z</dc:date>
    </item>
    <item>
      <title>Re: obtaining Month, Year combinations based on a Date prompt input</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/obtaining-Month-Year-combinations-based-on-a-Date-prompt-input/m-p/826772#M41200</link>
      <description>&lt;P&gt;Thank you very much&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":folded_hands:"&gt;🙏&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Aug 2022 03:34:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/obtaining-Month-Year-combinations-based-on-a-Date-prompt-input/m-p/826772#M41200</guid>
      <dc:creator>madara155</dc:creator>
      <dc:date>2022-08-03T03:34:29Z</dc:date>
    </item>
    <item>
      <title>Re: obtaining Month, Year combinations based on a Date prompt input</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/obtaining-Month-Year-combinations-based-on-a-Date-prompt-input/m-p/826773#M41201</link>
      <description>&lt;P&gt;Following line is giving the Selected_month_no as a single digit no (for July it is giving 7 instead of 07).&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;%let&lt;/FONT&gt; Selected_month_no =&lt;FONT color="#0000FF"&gt;%sysfunc&lt;/FONT&gt;(putn(&amp;amp;userdatevalue,month2.));&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Any thoughts on how to get it as a two digit value? I tried using z2. but I think I did it incorrectly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again&lt;/P&gt;</description>
      <pubDate>Wed, 03 Aug 2022 03:46:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/obtaining-Month-Year-combinations-based-on-a-Date-prompt-input/m-p/826773#M41201</guid>
      <dc:creator>madara155</dc:creator>
      <dc:date>2022-08-03T03:46:05Z</dc:date>
    </item>
    <item>
      <title>Re: obtaining Month, Year combinations based on a Date prompt input</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/obtaining-Month-Year-combinations-based-on-a-Date-prompt-input/m-p/826862#M41211</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/428921"&gt;@madara155&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Following line is giving the Selected_month_no as a single digit no (for July it is giving 7 instead of 07).&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;%let&lt;/FONT&gt; Selected_month_no =&lt;FONT color="#0000FF"&gt;%sysfunc&lt;/FONT&gt;(putn(&amp;amp;userdatevalue,month2.));&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Any thoughts on how to get it as a two digit value? I tried using z2. but I think I did it incorrectly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks again&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Please show what you did when you "tried using Z2.".&lt;/P&gt;</description>
      <pubDate>Wed, 03 Aug 2022 13:26:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/obtaining-Month-Year-combinations-based-on-a-Date-prompt-input/m-p/826862#M41211</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-08-03T13:26:06Z</dc:date>
    </item>
  </channel>
</rss>

