<?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: Date Prompts in SAS and Macro variables in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Date-Prompts-in-SAS-and-Macro-variables/m-p/821450#M41000</link>
    <description>&lt;P&gt;If you only need the macro variables then just use macro code to convert the string that is in the SelectedMonth macro variable into the strings you want in the&amp;nbsp;Month_, Year_, ColumnHead&amp;nbsp; macro variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let month_=%substr(&amp;amp;selectedmonth,3,3);
%let year_=%substr(&amp;amp;selectedmonth,8,2);
%let columnhead=&amp;amp;month_.-&amp;amp;year_. ;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you aren't running the code inside macro there is no need to force MONTH_ and the othe rmacro variables into the GLOBAL symbol table.&amp;nbsp; Any macro variable created in open code is by definition going to be in the GLOBAL macro table as it will be the only one that is active if no macro are currently executing.&lt;/P&gt;</description>
    <pubDate>Mon, 04 Jul 2022 02:24:03 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-07-04T02:24:03Z</dc:date>
    <item>
      <title>Date Prompts in SAS and Macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Date-Prompts-in-SAS-and-Macro-variables/m-p/821441#M40998</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;I am trying to get a user input (month and year from user) via "&lt;STRONG&gt;date prompt&lt;/STRONG&gt;". This input get assigned to a macro variable called &lt;STRONG&gt;&lt;EM&gt;SELECTEDMONTH&lt;/EM&gt; &lt;/STRONG&gt;(this is how it is displayed in the log: &lt;EM&gt;&lt;STRONG&gt;%LET SelectedMonth = 01Aug2022&lt;/STRONG&gt;;&lt;/EM&gt;).&lt;/P&gt;&lt;P&gt;Then I am trying to create&amp;nbsp; few other global macro variable based on this SelectedMonth as follows:&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" color="#0000FF"&gt;%global ColumnHead dummystartValue1;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" color="#0000FF"&gt;%global month_ dummystartValue2;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" color="#0000FF"&gt;%global year_ dummystartValue3;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" color="#0000FF"&gt;data test;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" color="#0000FF"&gt;/*extract the three letters corresponding to Month*/&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" color="#0000FF"&gt;month_ = substr("&amp;amp;SelectedMonth",3,3);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" color="#0000FF"&gt;/*extract the last two digits corresponding to year*/&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" color="#0000FF"&gt;year_ = substr("&amp;amp;SelectedMonth",8,2);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" color="#0000FF"&gt;/*Create a new variable holding the month and year*/&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" color="#0000FF"&gt;ColumnHead = catx("-",month_,year_);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" color="#0000FF"&gt;output;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" color="#0000FF"&gt;run;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000000"&gt;Following is the output I see:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="madara155_0-1656896358661.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/72903iEA448DA2DF6E02CF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="madara155_0-1656896358661.png" alt="madara155_0-1656896358661.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Although I can see the above outputs,&amp;nbsp; when I print all the macro variables at the end&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;Month_, Year_, ColumnHead&lt;/EM&gt;&lt;/STRONG&gt;&amp;nbsp;&lt;EM&gt;&lt;STRONG&gt;macros&lt;/STRONG&gt; &lt;/EM&gt;have no values displayed in the log (but&amp;nbsp;&lt;EM&gt;&lt;STRONG&gt;SelectedMonth has the original value)&lt;/STRONG&gt;&lt;/EM&gt;.&lt;/P&gt;&lt;P&gt;Having defined them as GLOBAL, I thought their values will get updated and retain those values. But it seems I am missing something.&lt;/P&gt;&lt;P&gt;Can someone please explain me what is going on here?&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jul 2022 01:04:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Date-Prompts-in-SAS-and-Macro-variables/m-p/821441#M40998</guid>
      <dc:creator>madara155</dc:creator>
      <dc:date>2022-07-04T01:04:32Z</dc:date>
    </item>
    <item>
      <title>Re: Date Prompts in SAS and Macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Date-Prompts-in-SAS-and-Macro-variables/m-p/821448#M40999</link>
      <description>&lt;P&gt;Where is the code that you used to assign values to the macro variables?&lt;/P&gt;
&lt;P&gt;All I see is the code to generate the dataset named TEST.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jul 2022 01:59:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Date-Prompts-in-SAS-and-Macro-variables/m-p/821448#M40999</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-07-04T01:59:16Z</dc:date>
    </item>
    <item>
      <title>Re: Date Prompts in SAS and Macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Date-Prompts-in-SAS-and-Macro-variables/m-p/821450#M41000</link>
      <description>&lt;P&gt;If you only need the macro variables then just use macro code to convert the string that is in the SelectedMonth macro variable into the strings you want in the&amp;nbsp;Month_, Year_, ColumnHead&amp;nbsp; macro variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let month_=%substr(&amp;amp;selectedmonth,3,3);
%let year_=%substr(&amp;amp;selectedmonth,8,2);
%let columnhead=&amp;amp;month_.-&amp;amp;year_. ;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you aren't running the code inside macro there is no need to force MONTH_ and the othe rmacro variables into the GLOBAL symbol table.&amp;nbsp; Any macro variable created in open code is by definition going to be in the GLOBAL macro table as it will be the only one that is active if no macro are currently executing.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jul 2022 02:24:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Date-Prompts-in-SAS-and-Macro-variables/m-p/821450#M41000</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-07-04T02:24:03Z</dc:date>
    </item>
    <item>
      <title>Re: Date Prompts in SAS and Macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Date-Prompts-in-SAS-and-Macro-variables/m-p/821461#M41001</link>
      <description>&lt;P&gt;Thanks Tom.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jul 2022 07:23:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Date-Prompts-in-SAS-and-Macro-variables/m-p/821461#M41001</guid>
      <dc:creator>madara155</dc:creator>
      <dc:date>2022-07-04T07:23:38Z</dc:date>
    </item>
    <item>
      <title>Re: Date Prompts in SAS and Macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Date-Prompts-in-SAS-and-Macro-variables/m-p/821474#M41005</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%global ColumnHead dummystartValue1;
%global month_ dummystartValue2;
%global year_ dummystartValue3;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is incorrect syntax if you are trying to assign values to macro variables. %GLOBAL does not assign values. Instead, I think you want this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET SelectedMonth = 01Aug2022;
data _null_;
    sasdate=input("&amp;amp;selectedmonth"d,date9.);
    month_ = month(sasdate);
    year_=year(sasdate);
    ColumnHead = catx("-",month_,year_);
    /* Create macro variables and assign values using CALL SYMPUTX */
   call symputx('dummystartvalue1',columnhead);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now that I have given you some code, let me also add that this is normally a very bad idea to include calendar information in variable names. You will work very hard to do things that are much simpler to do .Is the reason you want a calendar value in a variable name because you want to produce a report where one of the columns is headed by "Aug-22"? If so, forget all this macro use and instead use PROC REPORT, it is much simpler, no macros or macro variables needed, macros and macro variables causing lots of problem for beginners (as you have seen).&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jul 2022 12:18:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Date-Prompts-in-SAS-and-Macro-variables/m-p/821474#M41005</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-07-04T12:18:40Z</dc:date>
    </item>
  </channel>
</rss>

