<?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: PROC SQL Date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Date/m-p/440576#M110078</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;new_date = month(input('01'!!substr(date,1,3)!!'20'!!substr(date,5,2),date9.));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The concatenated strings result in a "typical SAS" date notation, which can be converted to a SAS date, and from that the month() function extracts your desired value.&lt;/P&gt;</description>
    <pubDate>Tue, 27 Feb 2018 16:50:17 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-02-27T16:50:17Z</dc:date>
    <item>
      <title>PROC SQL Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Date/m-p/440530#M110052</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have written a datastep using PROC SQL and have a date variable called 'Date' which is a character format $15. The variable outputs look like&lt;/P&gt;&lt;P&gt;Dec-17&lt;/P&gt;&lt;P&gt;Jan-18 etc.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to create a new variable which provides the month number only but not sure how to do it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I would like the following if possible -&amp;nbsp;&lt;/P&gt;&lt;P&gt;"date" variable = Dec-17 then I want "New Date" variable to display 12&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;"date" variable = Jan-18 then I want "New Date" variable to display 1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;It doesn't matter if the year changes, I just need the month number.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Current code:&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table work.data_new as&lt;BR /&gt;select&lt;BR /&gt;P_usage,&lt;BR /&gt;Date,&lt;BR /&gt;amount&lt;/P&gt;&lt;P&gt;from R.Mth;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any idea how to do this please?&lt;/P&gt;</description>
      <pubDate>Tue, 27 Feb 2018 15:34:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Date/m-p/440530#M110052</guid>
      <dc:creator>KC_16</dc:creator>
      <dc:date>2018-02-27T15:34:27Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Date/m-p/440535#M110056</link>
      <description>&lt;P&gt;1. Remove the dash using COMPRESS&lt;/P&gt;
&lt;P&gt;2. Convert to date using INPUT()&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. Use MONTH() function to convert to a numeric month&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
x='Dec-17';
y = compress(x, '-');
z=input(y, monyy5.);
month_num = month(z);
answer1step = month(input(compress(x, '-'), monyy5.));
run;

proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/195960"&gt;@KC_16&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have written a datastep using PROC SQL and have a date variable called 'Date' which is a character format $15. The variable outputs look like&lt;/P&gt;
&lt;P&gt;Dec-17&lt;/P&gt;
&lt;P&gt;Jan-18 etc.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to create a new variable which provides the month number only but not sure how to do it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I would like the following if possible -&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"date" variable = Dec-17 then I want "New Date" variable to display 12&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;"date" variable = Jan-18 then I want "New Date" variable to display 1&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;It doesn't matter if the year changes, I just need the month number.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Current code:&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table work.data_new as&lt;BR /&gt;select&lt;BR /&gt;P_usage,&lt;BR /&gt;Date,&lt;BR /&gt;amount&lt;/P&gt;
&lt;P&gt;from R.Mth;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any idea how to do this please?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Feb 2018 15:51:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Date/m-p/440535#M110056</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-27T15:51:59Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Date/m-p/440566#M110074</link>
      <description>&lt;P&gt;I have tried to include this within my code but can't get it to work and I don't completely understand the syntax you used to help demonstrate the fix sorry?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table work.data_new as&lt;BR /&gt;select&lt;BR /&gt;P_usage,&lt;BR /&gt;Date,&lt;/P&gt;&lt;P&gt;Date&amp;nbsp;= month(input(compress(Date, '-'), monyy5.)),&lt;BR /&gt;amount&lt;/P&gt;&lt;P&gt;from R.Mth;&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Feb 2018 16:42:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Date/m-p/440566#M110074</guid>
      <dc:creator>KC_16</dc:creator>
      <dc:date>2018-02-27T16:42:00Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Date/m-p/440576#M110078</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;new_date = month(input('01'!!substr(date,1,3)!!'20'!!substr(date,5,2),date9.));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The concatenated strings result in a "typical SAS" date notation, which can be converted to a SAS date, and from that the month() function extracts your desired value.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Feb 2018 16:50:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Date/m-p/440576#M110078</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-02-27T16:50:17Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Date/m-p/440577#M110079</link>
      <description>&lt;P&gt;You don't create variables that way in SQL....see the example below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;month(input(compress(Date, '-'), monyy5.)) as MONTH, &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Feb 2018 16:50:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-Date/m-p/440577#M110079</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-27T16:50:23Z</dc:date>
    </item>
  </channel>
</rss>

