<?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 convert date stored as character to numric in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-date-stored-as-character-to-numric/m-p/780337#M248637</link>
    <description>&lt;P&gt;Please post the log.&lt;/P&gt;</description>
    <pubDate>Tue, 16 Nov 2021 06:27:36 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2021-11-16T06:27:36Z</dc:date>
    <item>
      <title>How to convert date stored as character to numric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-date-stored-as-character-to-numric/m-p/780304#M248623</link>
      <description>&lt;P&gt;Hello team,&lt;/P&gt;
&lt;P&gt;I have this code and I can't find anything in google search as how to convert date to numeric to use it in year function. Year function only accepts numeric argument:&lt;/P&gt;
&lt;PRE&gt;data mydata;
set readfromhere;
date1= Input(Dateofserv, mmddyy10.);
Where year(date1)=2021;
run;&lt;/PRE&gt;
&lt;P&gt;It says that year function accepts numeric in year function. No idea how to convert DateofServ into numeric.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Aauslie&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Nov 2021 21:35:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-date-stored-as-character-to-numric/m-p/780304#M248623</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2021-11-15T21:35:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert date stored as character to numric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-date-stored-as-character-to-numric/m-p/780306#M248624</link>
      <description>&lt;P&gt;The data step Where really only uses variables from the data set on the SET statement. You should have gotten an error unless the variable DATE1 already existed in your data.&lt;/P&gt;
&lt;P&gt;Since you are adding a variable you would use&lt;/P&gt;
&lt;PRE&gt;IF year(date1)=2021;&lt;/PRE&gt;
&lt;P&gt;to subset data on the output data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A very brief example:&lt;/P&gt;
&lt;PRE&gt;22   data have;
23      x='12/31/2021';
24   run;

NOTE: The data set WORK.HAVE has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.04 seconds
      cpu time            0.01 seconds


25
26   data example1;
27     set have;
28      date1= Input(x, mmddyy10.);
29      Where year(date1)=2021;
&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;ERROR: Variable date1 is not on file WORK.HAVE.&lt;/STRONG&gt;&lt;/FONT&gt;
30      format date1 mmddyy10.;
31   run;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.EXAMPLE1 may be incomplete.  When this step was stopped there were 0
         observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


32
33   data example2;
34     set have;
35      date1= Input(x, mmddyy10.);
36      if year(date1)=2021;
37      format date1 mmddyy10.;
38   run;

NOTE: There were 1 observations read from the data set WORK.HAVE.
NOTE: The data set WORK.EXAMPLE2 has 1 observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Nov 2021 22:21:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-date-stored-as-character-to-numric/m-p/780306#M248624</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-11-15T22:21:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert date stored as character to numric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-date-stored-as-character-to-numric/m-p/780337#M248637</link>
      <description>&lt;P&gt;Please post the log.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Nov 2021 06:27:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-date-stored-as-character-to-numric/m-p/780337#M248637</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-11-16T06:27:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert date stored as character to numric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-date-stored-as-character-to-numric/m-p/780361#M248643</link>
      <description>&lt;P&gt;You do not have an issue with the type conversion, you have an issue with the incorrect use of WHERE, which can only filter on variables present in the incoming dataset(s). The log (Maxim 2) should reveal that.&lt;/P&gt;
&lt;P&gt;Use a&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/lestmtsref/p1cxl8ifdt8u0gn12wqbji8o5fq1.htm" target="_blank" rel="noopener"&gt;subsetting IF&lt;/A&gt;&amp;nbsp;instead.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Nov 2021 08:31:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-date-stored-as-character-to-numric/m-p/780361#M248643</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-11-16T08:31:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert date stored as character to numric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-date-stored-as-character-to-numric/m-p/780411#M248672</link>
      <description>&lt;P&gt;You have a perfectly good character variable.&amp;nbsp; It contains the information needed to subset the data.&amp;nbsp; Why is anything being converted to numeric?&amp;nbsp; If your character variable is truly in mmddyy10 format, just use:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where substr(dateofServ, 7) = '2021';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If there are variations in how the character variable appears and it isn't always in mmddyy10 format, we would have to explore further and perhaps make the statement slightly longer.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Nov 2021 13:00:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-date-stored-as-character-to-numric/m-p/780411#M248672</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2021-11-16T13:00:35Z</dc:date>
    </item>
  </channel>
</rss>

