<?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: How to extract months from dates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-months-from-dates/m-p/792072#M253789</link>
    <description>&lt;P&gt;So you already have code that throws an ERROR? Why didn't you post the log?&lt;/P&gt;</description>
    <pubDate>Tue, 25 Jan 2022 07:24:17 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2022-01-25T07:24:17Z</dc:date>
    <item>
      <title>How to extract months from dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-months-from-dates/m-p/791758#M253668</link>
      <description>&lt;PRE&gt;data test;
input  memberID $ DateOfService :ddmmyy10.;
format DateOfService ddmmyy10.;
datalines;
123 01/02/2021
124 02/02/2022
124 01/02/2022
156 09/08/2018
144 10/12/2019
;
run;

data want;
format month $3.;
set test;
run;

data want2;
set want;
select (DateOfService);
when (Month(DateofService) = 01) Then Month "Jan";
when (Month(DateofService) = 02) Then Month "Feb";
Otherwise ' ';
end;
run;&lt;/PRE&gt;
&lt;P&gt;Hello SAS Programmers;&lt;/P&gt;
&lt;P&gt;I need to pull the month name from a column named DateOfService which has number data type with when. Any tips?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second question is when I wanted to enter date in input statement, I needed to add this part:&amp;nbsp;DateOfService :ddmmyy10. Without it, the result was not correct. Can anyone please tell me what &amp;nbsp;:ddmmyy10. serve for DateOfService? Does it instruct SAS how to read the date? If yes, do we need to instruct SAS how to read dates when we have a date variable?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I appreciate your help.&lt;/P&gt;
&lt;P&gt;Blue&amp;amp;Blue&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jan 2022 05:25:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-months-from-dates/m-p/791758#M253668</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2022-01-24T05:25:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract months from dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-months-from-dates/m-p/791759#M253669</link>
      <description>&lt;P&gt;First: How about this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set test;
  length Month $3;
  if DateOfService ne . then do;
    Month=substr(put(DateOfService,date9.),3,3);          /* result is like FEB */
    Month=propcase(substr(put(DateOfService,date9.),3,3));/* result is like Feb select as you like */
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you really want to use SELECT WHEN, write the following&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want2;
  set want;
  select (DateOfService);
    when (Month(DateofService) = 01) Month="Jan";
    when (Month(DateofService) = 02) Month="Feb";
    Otherwise Month=' ';
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second:&lt;/P&gt;
&lt;P&gt;Specify this if the value specified in datalines is written in the format ddmmyy10..&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;It instructs SAS how to read the date&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;do we need to instruct SAS how to read dates when we have a date variable?&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes.&lt;/P&gt;
&lt;P&gt;Otherwise, the SAS process may not complete successfully.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jan 2022 06:25:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-months-from-dates/m-p/791759#M253669</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2022-01-24T06:25:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract months from dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-months-from-dates/m-p/791760#M253670</link>
      <description>Because your WHEN statements specify a  complete comparison, you need to simplify the SELECT statement.  Use:&lt;BR /&gt;SELECT();&lt;BR /&gt;&lt;BR /&gt;For the second question, yes yes yes.  However, it is not clear from your data whether ddmmyy10. is correct.   Is the incoming data in that form, or is it in MMDDYY10. form?  You need to know and must use the instruction that matches what actually appears in the data.</description>
      <pubDate>Mon, 24 Jan 2022 06:27:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-months-from-dates/m-p/791760#M253670</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2022-01-24T06:27:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract months from dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-months-from-dates/m-p/791771#M253674</link>
      <description>&lt;PRE&gt;data want;
  set test;
  length Month $3;
  if DateOfService ne . then do;
    Month=substr(put(DateOfService,date9.),3,3);          /* result is like FEB */
    Month=propcase(substr(put(DateOfService,date9.),3,3));/* result is like Feb select as you like */
  end;
run;&lt;/PRE&gt;
&lt;P&gt;Hello team member,&lt;/P&gt;
&lt;P&gt;First solution: dates are like 03/12/2021, it is not text.&amp;nbsp;&lt;BR /&gt;All months as character have 3 characters. How does SAS distinguish this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think your second solution is the answer. Let me test it and get back to you.&lt;/P&gt;
&lt;P&gt;What would be the syntax if I want to write in process sql?&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;Refering to dates in datelines, thanks for clarification,&lt;/P&gt;
&lt;P&gt;I am so thankful,&lt;/P&gt;
&lt;P&gt;Blue&amp;amp;white&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jan 2022 07:12:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-months-from-dates/m-p/791771#M253674</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2022-01-24T07:12:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract months from dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-months-from-dates/m-p/791773#M253676</link>
      <description>&lt;P&gt;Hello team member,&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Because your WHEN statements specify a complete comparison, you need to simplify the SELECT statement. Use:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;SELECT();&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;Can you please kindly explain it more? If I select one variable, are the other variable included in the result?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;blue &amp;amp; white&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jan 2022 07:17:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-months-from-dates/m-p/791773#M253676</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2022-01-24T07:17:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract months from dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-months-from-dates/m-p/791774#M253677</link>
      <description>&lt;P&gt;Please try it first.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And check put function and DATE9. format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Same in SQL.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  select memberID,substr(put(DateOfService,date9.),3,3) as month 
  from test;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jan 2022 07:25:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-months-from-dates/m-p/791774#M253677</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2022-01-24T07:25:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract months from dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-months-from-dates/m-p/791778#M253678</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/202329"&gt;@GN0001&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello team member,&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Because your WHEN statements specify a complete comparison, you need to simplify the SELECT statement. Use:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;SELECT();&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;Can you please kindly explain it more? If I select one variable, are the other variable included in the result?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;blue &amp;amp; white&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/p09213s9jc2t99n1vx0omk2rh9ps.htm" target="_blank" rel="noopener"&gt;SELECT Statement&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's all in there.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jan 2022 07:44:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-months-from-dates/m-p/791778#M253678</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-01-24T07:44:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract months from dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-months-from-dates/m-p/791817#M253686</link>
      <description>&lt;P&gt;There has been a lot of other suggestions, but if you for some reason must use a SELECT statement, I think it should be done like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select (Month(DateOfService));
when (01) Month="Jan";
when (02) Month="Feb";
Otherwise;
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This calculates the MONTH function only once, not once for every line in the SELECT statement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I made the OTHERWISE statement empty, as the MONTH variable will already be empty, if nothing has been assigned to it first. The OTHERWISE is still necessary, else you will get an error when there is a value not in the first two months.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jan 2022 11:39:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-months-from-dates/m-p/791817#M253686</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2022-01-24T11:39:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract months from dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-months-from-dates/m-p/791851#M253701</link>
      <description>&lt;P&gt;Sorry, my mistake.&amp;nbsp; I thought you already knew at least the basics of the SELECT statement.&amp;nbsp; You did use it in the program you posted.&amp;nbsp; I won't make that mistake again.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm afraid that&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;is correct.&amp;nbsp; I can't exercise to make you stronger.&amp;nbsp; I can't eat right to make you healthier.&amp;nbsp; And I can't read the documentation to make you smarter.&amp;nbsp; There are some things you just have to do for yourself.&amp;nbsp; If you have specific questions, that's another story.&amp;nbsp; But it's not my job to read the documentation, summarize it for you, and compose examples to ensure that you understand it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just a word to the wise&amp;nbsp; I posted a nearly working solution.&amp;nbsp; Evidently, you didn't test it because you didn't post any results.&amp;nbsp; So I will give you the last piece of the solution.&amp;nbsp; In addition to what I posted, the OTHERWISE statement needs to be simplified as well:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;otherwise;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So that means your original program would have been correct, had you just removed some of the characters from it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jan 2022 14:02:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-months-from-dates/m-p/791851#M253701</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2022-01-24T14:02:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract months from dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-months-from-dates/m-p/791860#M253705</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;First solution: dates are like 03/12/2021, it is not text.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;The date variable is numeric and display like the string you showed then it contains a date value (number of days since 1960) and you displayed it with the MMDDYY or DDMMYY format so that it generated that 10 character string.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The format used to display a number does not change the number.&amp;nbsp; So you can still use the DATE format to convert the value in your date variable into a string that uses 3 characters for the month.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jan 2022 14:22:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-months-from-dates/m-p/791860#M253705</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-01-24T14:22:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract months from dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-months-from-dates/m-p/791891#M253716</link>
      <description>&lt;P&gt;MONNAME3. Format, and possibly not even need another variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;21   data example;
22      x=today();
23      put x= monname3.;
24   run;

x=Jan
&lt;/PRE&gt;
&lt;P&gt;You will find a LARGE number of ways to manipulate date appearances with just the default formats supplied by SAS. Plus you can role your own with Proc Format that would be honored by report and analysis procedures.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For almost any date, time or datetime value you must specify to SAS with an informat the structure of the values. Consider the sequence:&lt;/P&gt;
&lt;P&gt;01/02/03&lt;/P&gt;
&lt;P&gt;Depending on locality and usage that could represent: 1 February 2003 (or 1903), 2 January 2003 (or 1903) , 3 Februray 2001 (or 1901) . So you have to tell SAS which order the day, month and year appear in your values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS treats &lt;STRONG&gt;any variable&lt;/STRONG&gt; that has not been provided information somewhere (Informat statement, Attrib statement, in line informat) as numeric by default. Which is going to have issues with the / characters. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jan 2022 16:24:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-months-from-dates/m-p/791891#M253716</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-01-24T16:24:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract months from dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-months-from-dates/m-p/791924#M253734</link>
      <description>Hello Astounding,&lt;BR /&gt;Sorry, my mistake.  I thought you already knew at least the basics of the SELECT statement.&lt;BR /&gt;I wrote the code by myself and posted here. It was giving 8 errors and I fixed them all, except the last one that I couldn't, that is why, I posted here in this forum.&lt;BR /&gt;I know sql.&lt;BR /&gt;Respectfully,&lt;BR /&gt;BlueBlue</description>
      <pubDate>Mon, 24 Jan 2022 17:09:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-months-from-dates/m-p/791924#M253734</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2022-01-24T17:09:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract months from dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-months-from-dates/m-p/791929#M253738</link>
      <description>Hello,&lt;BR /&gt;I know sql and relational database management system. I did the code myself&lt;BR /&gt;and it gave me 8 errors and I fixed them one by one, still the last one&lt;BR /&gt;persisted.&lt;BR /&gt;&lt;BR /&gt;Last night, it was too late and I couldn't apply your solution. Please bear&lt;BR /&gt;with me.&lt;BR /&gt;&lt;BR /&gt;Blue&amp;amp;Blue&lt;BR /&gt;</description>
      <pubDate>Mon, 24 Jan 2022 17:19:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-months-from-dates/m-p/791929#M253738</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2022-01-24T17:19:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract months from dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-months-from-dates/m-p/792072#M253789</link>
      <description>&lt;P&gt;So you already have code that throws an ERROR? Why didn't you post the log?&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jan 2022 07:24:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-months-from-dates/m-p/792072#M253789</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-01-25T07:24:17Z</dc:date>
    </item>
  </channel>
</rss>

