<?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: Monname Results Do not match month names in proc SQL in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Monname-Results-Do-not-match-month-names-in-proc-SQL/m-p/697263#M37466</link>
    <description>Show the log from a query that does work and one that doesn't.</description>
    <pubDate>Fri, 06 Nov 2020 22:31:56 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2020-11-06T22:31:56Z</dc:date>
    <item>
      <title>Monname Results Do not match month names in proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Monname-Results-Do-not-match-month-names-in-proc-SQL/m-p/697262#M37465</link>
      <description>&lt;P&gt;Hi, I try to get month name from a date column (yyy-mm-dd) with the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA WANT;
SET X;
names=put(Date, monname.);
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and the new column (names) results are:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
select distinct names from WANT; quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sun538_0-1604701307860.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/51473iAF39EEB8B8C4455A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sun538_0-1604701307860.png" alt="sun538_0-1604701307860.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;However, when I run a query to get all records for each month name, &lt;STRONG&gt;it only works for only one month "September"&lt;/STRONG&gt;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
 select *
 from WANT 
 where names="January";
 quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Surprisingly, &lt;STRONG&gt;the query returns 0 records for all months except "September" (&lt;/STRONG&gt;&lt;CODE class=" language-sas"&gt;&lt;STRONG&gt;where names="September")&lt;/STRONG&gt;.&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;Could you please help find out why that happens and how to resolve it? Is it the issue with using "monname" format?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Nov 2020 22:28:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Monname-Results-Do-not-match-month-names-in-proc-SQL/m-p/697262#M37465</guid>
      <dc:creator>sun538</dc:creator>
      <dc:date>2020-11-06T22:28:29Z</dc:date>
    </item>
    <item>
      <title>Re: Monname Results Do not match month names in proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Monname-Results-Do-not-match-month-names-in-proc-SQL/m-p/697263#M37466</link>
      <description>Show the log from a query that does work and one that doesn't.</description>
      <pubDate>Fri, 06 Nov 2020 22:31:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Monname-Results-Do-not-match-month-names-in-proc-SQL/m-p/697263#M37466</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-11-06T22:31:56Z</dc:date>
    </item>
    <item>
      <title>Re: Monname Results Do not match month names in proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Monname-Results-Do-not-match-month-names-in-proc-SQL/m-p/697266#M37467</link>
      <description>&lt;P&gt;Since you are starting with a numeric valued date when you use the PUT function the result is right justified and there are leading spaces in most of the month names. So when you test for equality you have to remove the leading blanks.&lt;/P&gt;
&lt;PRE&gt;data want;
   do month=1 to 12;
      date=mdy(month,1,2020);
      names= put(date,monname.);
      output;
   end;
   format date date9.;
run;

proc sql;
 select *
 from WANT 
 where strip(names)="May";
 quit;

&lt;/PRE&gt;
&lt;P&gt;OR use&lt;/P&gt;
&lt;P&gt;put(date, monname. -L);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The -L will left justify the result of the Put.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Nov 2020 15:27:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Monname-Results-Do-not-match-month-names-in-proc-SQL/m-p/697266#M37467</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-11-09T15:27:18Z</dc:date>
    </item>
    <item>
      <title>Re: Monname Results Do not match month names in proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Monname-Results-Do-not-match-month-names-in-proc-SQL/m-p/697287#M37468</link>
      <description>&lt;P&gt;You are being confused by looking at ODS output instead of looking at the actual data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data months;
 do month=1 to 12 ;
   monname=put(mdy(month,1,1),monname.);
   output;
 end;
run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you look a the regular text output you can see the leading spaces.&lt;/P&gt;
&lt;PRE&gt;Obs    month     monname

  1       1       January
  2       2      February
  3       3         March
  4       4         April
  5       5           May
  6       6          June
  7       7          July
  8       8        August
  9       9     September
 10      10       October
 11      11      November
 12      12      December&lt;/PRE&gt;
&lt;P&gt;Either use the LEFT() function to remove the leading spaces. Or add the -L modifier on the end of the format specification so that the leading spaces are not saved to begin with.&lt;/P&gt;</description>
      <pubDate>Sat, 07 Nov 2020 05:03:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Monname-Results-Do-not-match-month-names-in-proc-SQL/m-p/697287#M37468</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-11-07T05:03:08Z</dc:date>
    </item>
  </channel>
</rss>

