<?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: Problem on converting character data to numeric data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Problem-on-converting-character-data-to-numeric-data/m-p/732233#M228175</link>
    <description>&lt;P&gt;Sorry dude, you still did it wrong and it definitely works.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=sashelp.stocks out=stocks;
by stock date;
run;

data want;
set stocks;
where stock = "IBM";
by date groupformat;
format date year4.;
if first.date then flag=1;
if last.date then flag=1;

run;

proc print data=want;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/377298"&gt;@Anddiy&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I've tried this, and did not work.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;CODE:&lt;BR /&gt;&lt;BR /&gt;DATA TEST_FORMAT;&lt;BR /&gt;SET mytable;&lt;BR /&gt;FORMAT DT_REFER YYMMN6.;&lt;BR /&gt;BY GROUPFORMAT DT_REFER;&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;In this case the group by didin't work, it is because if you just "format" a SAS DATE9. (Example: 19OCT2020) the sas will show you 202010, but for sas it's still 19OCT2020, because of that i have created a CHARACTER var for that and format that var to receive 202011....&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 08 Apr 2021 15:10:58 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2021-04-08T15:10:58Z</dc:date>
    <item>
      <title>Problem on converting character data to numeric data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-on-converting-character-data-to-numeric-data/m-p/732107#M228116</link>
      <description>&lt;P&gt;Hi Guys,&lt;/P&gt;&lt;P&gt;Im having some problems to convert a SAS char to a numeric sas date,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my project, i have a numeric column named DT_REFER, this column contains the date of my clients in sas DATE9. format ( Example: 19OCT2020), on my way in this project i needed to group by that data in a month format, so to do group by with data in sas i needed convert that DATE9. to a CHARACTER month format , i did it using a simple put function "PUT(DT_REFER, MMYYD.) AS DT_MONTH " on a proc sql with group by, now the original 19OCT2020 data has been converted to a character "10-2020" and the group by works normaly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But now i need to convert it back to a date format to send it to Teradata Database, and im having trouble to convert it back, i tried to do some input functions in a data step like that:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA CONVERT_BACK;&lt;/P&gt;&lt;P&gt;SET mybase;&lt;/P&gt;&lt;P&gt;DATA_BACK = input(DT_MONTH, MMYYD.);&lt;/P&gt;&lt;P&gt;RUN;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to get a 10-2020 in numeric date format, but all i get is a empty DATA_BACK with a "." in it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What i need to do to solve this?&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Apr 2021 22:41:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-on-converting-character-data-to-numeric-data/m-p/732107#M228116</guid>
      <dc:creator>Anddiy</dc:creator>
      <dc:date>2021-04-07T22:41:28Z</dc:date>
    </item>
    <item>
      <title>Re: Problem on converting character data to numeric data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-on-converting-character-data-to-numeric-data/m-p/732108#M228117</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/377298"&gt;@Anddiy&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi &lt;STRIKE&gt;Guys,&lt;/STRIKE&gt;&lt;/P&gt;
&lt;P&gt;Im having some problems to convert a SAS char to a numeric sas date,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In my project, i have a numeric column named DT_REFER, this column contains the date of my clients in sas DATE9. format ( Example: 19OCT2020), on my way &lt;FONT color="#FF6600"&gt;&lt;U&gt;&lt;STRONG&gt;in this project i needed to group by that data in a month format, so to do group by with data in sas i needed convert that DATE9. to a CHARACTER month format&lt;/STRONG&gt;&lt;/U&gt;&lt;/FONT&gt; , i did it using a simple put function "PUT(DT_REFER, MMYYD.) AS DT_MONTH " on a proc sql with group by, now the original 19OCT2020 data has been converted to a character "10-2020" and the group by works normaly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But now i need to convert it back to a date format to send it to Teradata Database, and im having trouble to convert it back, i tried to do some input functions in a data step like that:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA CONVERT_BACK;&lt;/P&gt;
&lt;P&gt;SET mybase;&lt;/P&gt;
&lt;P&gt;DATA_BACK = input(DT_MONTH, MMYYD.);&lt;/P&gt;
&lt;P&gt;RUN;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to get a 10-2020 in numeric date format, but all i get is a empty DATA_BACK with a "." in it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What i need to do to solve this?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Regarding the section I've highlighted in orange, that's fortunately wrong.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can just format the date and add the GROUPFORMAT option in the BY statement to tell SAS to group the data by the formatted value.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;YYMMN6. is a good format for year/month summary.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Apr 2021 23:02:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-on-converting-character-data-to-numeric-data/m-p/732108#M228117</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-04-07T23:02:33Z</dc:date>
    </item>
    <item>
      <title>Re: Problem on converting character data to numeric data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-on-converting-character-data-to-numeric-data/m-p/732109#M228118</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt;&amp;nbsp;i needed to group by that data in a month format&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You don't need to create a new variable&amp;nbsp;for this. Just apply a format to the date as you do the calculation.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Apr 2021 23:11:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-on-converting-character-data-to-numeric-data/m-p/732109#M228118</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-04-07T23:11:00Z</dc:date>
    </item>
    <item>
      <title>Re: Problem on converting character data to numeric data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-on-converting-character-data-to-numeric-data/m-p/732113#M228122</link>
      <description>&lt;P&gt;This works:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  date = '19OCT2020'd ;
  mmyy = put(date,mmyyd7.);
  date2 = input('01-'||mmyy,ddmmyy10.);
  put (_all_) (=);
  format date: date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;date=19OCT2020 mmyy=10-2020 date2=01OCT2020&lt;/PRE&gt;
&lt;P&gt;What type of BY statement are you using where you cannot use formatted values to group?&lt;/P&gt;
&lt;P&gt;Also why would you use a format that will not sort in the right order?&amp;nbsp; If you use that format 01-2021 will sort before 02-2020.&lt;/P&gt;
&lt;PRE&gt;760   data test;
761     date = '19OCT2020'd ;
762     yymm = put(date,yymmd7.);
763     date2 = input(cats(yymm,'-01'),yymmdd10.);
764     put (_all_) (=);
765     format date: date9.;
766   run;

date=19OCT2020 yymm=2020-10 date2=01OCT2020
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Apr 2021 23:19:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-on-converting-character-data-to-numeric-data/m-p/732113#M228122</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-04-07T23:19:11Z</dc:date>
    </item>
    <item>
      <title>Re: Problem on converting character data to numeric data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-on-converting-character-data-to-numeric-data/m-p/732114#M228123</link>
      <description>I've tried this, and did not work.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;CODE:&lt;BR /&gt;&lt;BR /&gt;DATA TEST_FORMAT;&lt;BR /&gt;SET mytable;&lt;BR /&gt;FORMAT DT_REFER YYMMN6.;&lt;BR /&gt;BY GROUPFORMAT DT_REFER;&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;In this case the group by didin't work, it is because if you just "format" a SAS DATE9. (Example: 19OCT2020) the sas will show you 202010, but for sas it's still 19OCT2020, because of that i have created a CHARACTER var for that and format that var to receive 202011....&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 07 Apr 2021 23:30:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-on-converting-character-data-to-numeric-data/m-p/732114#M228123</guid>
      <dc:creator>Anddiy</dc:creator>
      <dc:date>2021-04-07T23:30:07Z</dc:date>
    </item>
    <item>
      <title>Re: Problem on converting character data to numeric data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-on-converting-character-data-to-numeric-data/m-p/732117#M228125</link>
      <description>That worked for me, thanks man!&lt;BR /&gt;&lt;BR /&gt;Im change somethings to ajust in my code but works!&lt;BR /&gt;&lt;BR /&gt;Thanks a lot.</description>
      <pubDate>Wed, 07 Apr 2021 23:56:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-on-converting-character-data-to-numeric-data/m-p/732117#M228125</guid>
      <dc:creator>Anddiy</dc:creator>
      <dc:date>2021-04-07T23:56:31Z</dc:date>
    </item>
    <item>
      <title>Re: Problem on converting character data to numeric data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-on-converting-character-data-to-numeric-data/m-p/732233#M228175</link>
      <description>&lt;P&gt;Sorry dude, you still did it wrong and it definitely works.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=sashelp.stocks out=stocks;
by stock date;
run;

data want;
set stocks;
where stock = "IBM";
by date groupformat;
format date year4.;
if first.date then flag=1;
if last.date then flag=1;

run;

proc print data=want;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/377298"&gt;@Anddiy&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I've tried this, and did not work.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;CODE:&lt;BR /&gt;&lt;BR /&gt;DATA TEST_FORMAT;&lt;BR /&gt;SET mytable;&lt;BR /&gt;FORMAT DT_REFER YYMMN6.;&lt;BR /&gt;BY GROUPFORMAT DT_REFER;&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;In this case the group by didin't work, it is because if you just "format" a SAS DATE9. (Example: 19OCT2020) the sas will show you 202010, but for sas it's still 19OCT2020, because of that i have created a CHARACTER var for that and format that var to receive 202011....&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Apr 2021 15:10:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-on-converting-character-data-to-numeric-data/m-p/732233#M228175</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-04-08T15:10:58Z</dc:date>
    </item>
  </channel>
</rss>

