<?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: YYMMN6 format variable conversion to character in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/YYMMN6-format-variable-conversion-to-character/m-p/821061#M324142</link>
    <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;data _null_;&lt;BR /&gt;Format last_mnth yymmn6.;&lt;BR /&gt;format lst_mnth $6.;&lt;BR /&gt;format char_mnth $6.;&lt;BR /&gt;last_month = intnx('month',today(),-1,'E');&lt;BR /&gt;call symput("last_mnth", put (last_month, YYMMN6.));&lt;BR /&gt;&lt;FONT color="#FF6600"&gt;%put &amp;amp;=last_mnth.;&lt;/FONT&gt; &lt;BR /&gt;run;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The %put-statement won't work as expected, because it is resolved before the data step is executed. From the second program execution you will see the value of the prior execution. Moving the %put statement after run; solves the problem.&lt;/P&gt;</description>
    <pubDate>Thu, 30 Jun 2022 04:51:57 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2022-06-30T04:51:57Z</dc:date>
    <item>
      <title>YYMMN6 format variable conversion to character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/YYMMN6-format-variable-conversion-to-character/m-p/821023#M324115</link>
      <description>&lt;P&gt;Have to create a variable to be used in multiple SQL statements in format YYMMN6.&lt;/P&gt;
&lt;P&gt;Need current month&amp;nbsp; in this format and previous month.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;%let this_month =%sysfunc(date(), yymmn6.) ;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;EM&gt;&amp;nbsp;/current month in YYMMN6.&lt;/EM&gt;&lt;BR /&gt;%put &amp;amp;this_month.;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;BR /&gt;Format last_mnth yymmn6.;&lt;BR /&gt;format lst_mnth $6.;&lt;BR /&gt;format char_mnth $6.;&lt;BR /&gt;last_month = intnx('month',today(),-1,'E');&lt;BR /&gt;call symput("last_mnth", put (last_month, YYMMN6.));&lt;BR /&gt;%put &amp;amp;last_mnth.;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Code gives me last month in correct format, but as a numeric and variable in dataset is character so getting the error message below when attempting to run SQL:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;LOG:&lt;/P&gt;
&lt;P&gt;SYMBOLGEN: Macro variable THIS_MNTH resolves to 202206&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;EM&gt; &amp;nbsp;/*all good, current month&lt;/EM&gt;&lt;BR /&gt;31 where yrmo = &amp;amp;last_mnth.;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;EM&gt; /where cause in PROC SQL&lt;/EM&gt;&lt;BR /&gt;SYMBOLGEN: Macro variable LAST_MNTH resolves to 202205&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;EM&gt; /*all good, last month&lt;/EM&gt;&lt;BR /&gt;ERROR: Expression using equals (=) has components that are of different data types.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do I convert variable "last_mnth" to a character in the macro, so I can use it throughout the remaining code?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jun 2022 20:44:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/YYMMN6-format-variable-conversion-to-character/m-p/821023#M324115</guid>
      <dc:creator>Jumboshrimps</dc:creator>
      <dc:date>2022-06-29T20:44:30Z</dc:date>
    </item>
    <item>
      <title>Re: YYMMN6 format variable conversion to character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/YYMMN6-format-variable-conversion-to-character/m-p/821024#M324116</link>
      <description>&lt;P&gt;In this case I think you just need quotes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where yrmo = "&amp;amp;last_mnth.";      &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 Jun 2022 20:47:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/YYMMN6-format-variable-conversion-to-character/m-p/821024#M324116</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-06-29T20:47:30Z</dc:date>
    </item>
    <item>
      <title>Re: YYMMN6 format variable conversion to character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/YYMMN6-format-variable-conversion-to-character/m-p/821025#M324117</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/28840"&gt;@Jumboshrimps&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;LOG:&lt;/P&gt;
&lt;P&gt;SYMBOLGEN: Macro variable THIS_MNTH resolves to 202206&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;EM&gt; &amp;nbsp;/*all good, current month&lt;/EM&gt;&lt;BR /&gt;31 where yrmo = &amp;amp;last_mnth.;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;EM&gt; /where cause in PROC SQL&lt;/EM&gt;&lt;BR /&gt;SYMBOLGEN: Macro variable LAST_MNTH resolves to 202205&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;EM&gt; /*all good, last month&lt;/EM&gt;&lt;BR /&gt;ERROR: Expression using equals (=) has components that are of different data types.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The ERROR indicates YRMO is character, normally you wouldn't store calendar information as character variables ... but let me ask you a simple question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have YRMO as a character variable and you want to test to see if it is a specific value, please finish this WHERE statement without macro variables, what should it look like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;WHERE YRMO = _______________ ;&amp;nbsp;&amp;nbsp;&amp;nbsp; (you fill in the blank with something that will not generate a syntax error)&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jun 2022 20:55:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/YYMMN6-format-variable-conversion-to-character/m-p/821025#M324117</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-06-29T20:55:11Z</dc:date>
    </item>
    <item>
      <title>Re: YYMMN6 format variable conversion to character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/YYMMN6-format-variable-conversion-to-character/m-p/821034#M324125</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/28840"&gt;@Jumboshrimps&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Remember that a macro variable is not defined with a data type (char or num). The macro variable has a content, and when the variable is resolved, the content is inserted instead, so it works the same way as if the value was written from the keyboard.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the variable resolves to digits only, it can be used without quotes in places where a number is legal syntax, but if the content calls for a character value, ex.in a comparison with a char variable in a where statement, the value should be written in quotes, so&amp;nbsp;the macro variable must be enclosed in double quotes (double, because it will not resolve in single quotes).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jun 2022 21:45:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/YYMMN6-format-variable-conversion-to-character/m-p/821034#M324125</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2022-06-29T21:45:06Z</dc:date>
    </item>
    <item>
      <title>Re: YYMMN6 format variable conversion to character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/YYMMN6-format-variable-conversion-to-character/m-p/821053#M324138</link>
      <description>&lt;P&gt;From the error message YRMO variable is character and you tried to compare it to the number 202,205.00 instead of the string '202205' because you ran this code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where yrmo = 202205;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;instead of&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where yrmo = "202205";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Your data step is also confused.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You are running the %PUT to echo the values of LAST_MNTH before the data step has had a chance to create it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  last_month = intnx('month',today(),-1,'E');
  call symputx("last_mnth", put(last_month, YYMMN6.));
run;

%put &amp;amp;=last_mnth;  
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jun 2022 01:04:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/YYMMN6-format-variable-conversion-to-character/m-p/821053#M324138</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-06-30T01:04:06Z</dc:date>
    </item>
    <item>
      <title>Re: YYMMN6 format variable conversion to character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/YYMMN6-format-variable-conversion-to-character/m-p/821061#M324142</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;data _null_;&lt;BR /&gt;Format last_mnth yymmn6.;&lt;BR /&gt;format lst_mnth $6.;&lt;BR /&gt;format char_mnth $6.;&lt;BR /&gt;last_month = intnx('month',today(),-1,'E');&lt;BR /&gt;call symput("last_mnth", put (last_month, YYMMN6.));&lt;BR /&gt;&lt;FONT color="#FF6600"&gt;%put &amp;amp;=last_mnth.;&lt;/FONT&gt; &lt;BR /&gt;run;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The %put-statement won't work as expected, because it is resolved before the data step is executed. From the second program execution you will see the value of the prior execution. Moving the %put statement after run; solves the problem.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jun 2022 04:51:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/YYMMN6-format-variable-conversion-to-character/m-p/821061#M324142</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-06-30T04:51:57Z</dc:date>
    </item>
  </channel>
</rss>

