<?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: Stripping non-specific characters from string by number in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Stripping-non-specific-characters-from-string-by-number/m-p/963062#M375254</link>
    <description>&lt;P&gt;Thanks - it's a character variable, and I successfully used the first block of code to make the variable into "yyyy-mm-dd hh:mm:ss" format. However, I need it to be a numeric variable in DATETIME format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried the code below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Start_Datetime_num = input(Start_Datetime_2, 8.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But got the constant error:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOTE: Invalid argument to function INPUT at line ## column ##&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And the&amp;nbsp;&lt;CODE class=" language-sas"&gt;Start_Datetime_num&lt;/CODE&gt; variable is entirely blank. Could you help? Thank you.&lt;/P&gt;</description>
    <pubDate>Mon, 31 Mar 2025 23:40:42 GMT</pubDate>
    <dc:creator>confooseddesi89</dc:creator>
    <dc:date>2025-03-31T23:40:42Z</dc:date>
    <item>
      <title>Stripping non-specific characters from string by number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Stripping-non-specific-characters-from-string-by-number/m-p/963049#M375247</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a weird format for datetime in a dataset where the datetime is followed by a decimal point and three random numbers. For example:&lt;/P&gt;
&lt;P&gt;Start_Datetime&lt;/P&gt;
&lt;P&gt;2022-06-26 19:43:00.358&lt;/P&gt;
&lt;P&gt;2022-06-26 21:33:13.403&lt;BR /&gt;2022-08-30 07:26:04.178&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's possible those last three numbers refer to the millisecond, but I don't need this information. I want to make the format "yyyy-mm-dd hh:mm:ss" and datetime, which requires deleting the last four characters, the decimal and the three numbers. Could someone provide code? I've Googled around and only can find code to delete&amp;nbsp;&lt;EM&gt;specific&amp;nbsp;&lt;/EM&gt;characters. Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 31 Mar 2025 18:52:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Stripping-non-specific-characters-from-string-by-number/m-p/963049#M375247</guid>
      <dc:creator>confooseddesi89</dc:creator>
      <dc:date>2025-03-31T18:52:27Z</dc:date>
    </item>
    <item>
      <title>Re: Stripping non-specific characters from string by number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Stripping-non-specific-characters-from-string-by-number/m-p/963050#M375248</link>
      <description>&lt;P&gt;First question you need to answer is what TYPE of variable you have.&amp;nbsp; It is character variable? Or a numeric variable with a display format that is making print those strings that have colons and periods in them?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it is a character variable and the month number and day of month numbers always use 2 digits just use SUBSTR() take the first 19 characters.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;short_string = substr(long_string,1,19);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I they are not so consistent then just use substr to take up to the place where the period is (if there is one).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if index(long_string,'.') then 
  short_string = substr(long_string,1,index(long_string,'.')-1)
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you have a numeric variable then just change the format you are using by removing the 3 from the end that is telling SAS you want 3 decimal places.&amp;nbsp; If you want to remove the milliseconds from the value you could use the INT() function to just take the whole number of seconds.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;integer_value = int(real_value);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 31 Mar 2025 19:13:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Stripping-non-specific-characters-from-string-by-number/m-p/963050#M375248</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-03-31T19:13:31Z</dc:date>
    </item>
    <item>
      <title>Re: Stripping non-specific characters from string by number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Stripping-non-specific-characters-from-string-by-number/m-p/963051#M375249</link>
      <description>&lt;P&gt;This is just a formatting change. For datetime values, the underlying value is always the number of seconds since 01JAN1960:00:00:00, and then formatting changes the appearance to something that humans can read. So pick a format that matches what you want, like foprmat datetime19.0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
Start_Datetime='2022-06-26 19:43:00.358'dt; output;
Start_Datetime='2022-06-26 21:33:13.403'dt; output;
Start_Datetime='2022-08-30 07:26:04.178'dt; output;
format start_datetime datetime25.6;
run;
data want;
    set have;
    format start_datetime datetime19.0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 31 Mar 2025 19:15:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Stripping-non-specific-characters-from-string-by-number/m-p/963051#M375249</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-03-31T19:15:14Z</dc:date>
    </item>
    <item>
      <title>Re: Stripping non-specific characters from string by number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Stripping-non-specific-characters-from-string-by-number/m-p/963052#M375250</link>
      <description>&lt;P&gt;If that isn't close enough to what you want, you can create your own date/time format to make it look exactly the way you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
    picture myfmt
        low-high='%Y-%0m-%0d %0H:%0M:%0s' (datatype=datetime) ;
run;
data want;
    set have;
    format start_datetime myfmt19.;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 31 Mar 2025 19:42:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Stripping-non-specific-characters-from-string-by-number/m-p/963052#M375250</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-03-31T19:42:15Z</dc:date>
    </item>
    <item>
      <title>Re: Stripping non-specific characters from string by number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Stripping-non-specific-characters-from-string-by-number/m-p/963062#M375254</link>
      <description>&lt;P&gt;Thanks - it's a character variable, and I successfully used the first block of code to make the variable into "yyyy-mm-dd hh:mm:ss" format. However, I need it to be a numeric variable in DATETIME format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried the code below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Start_Datetime_num = input(Start_Datetime_2, 8.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But got the constant error:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOTE: Invalid argument to function INPUT at line ## column ##&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And the&amp;nbsp;&lt;CODE class=" language-sas"&gt;Start_Datetime_num&lt;/CODE&gt; variable is entirely blank. Could you help? Thank you.&lt;/P&gt;</description>
      <pubDate>Mon, 31 Mar 2025 23:40:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Stripping-non-specific-characters-from-string-by-number/m-p/963062#M375254</guid>
      <dc:creator>confooseddesi89</dc:creator>
      <dc:date>2025-03-31T23:40:42Z</dc:date>
    </item>
    <item>
      <title>Re: Stripping non-specific characters from string by number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Stripping-non-specific-characters-from-string-by-number/m-p/963064#M375256</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  Date_String = '2022-06-26 19:43:00.358';
  DateTime = input (Date_String, anydtdtm23.);
  format DateTime datetime22.;
  put _all_;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 31 Mar 2025 23:51:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Stripping-non-specific-characters-from-string-by-number/m-p/963064#M375256</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2025-03-31T23:51:45Z</dc:date>
    </item>
    <item>
      <title>Re: Stripping non-specific characters from string by number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Stripping-non-specific-characters-from-string-by-number/m-p/963069#M375259</link>
      <description>&lt;P&gt;Thanks! Worked great.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Apr 2025 00:49:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Stripping-non-specific-characters-from-string-by-number/m-p/963069#M375259</guid>
      <dc:creator>confooseddesi89</dc:creator>
      <dc:date>2025-04-01T00:49:31Z</dc:date>
    </item>
    <item>
      <title>Re: Stripping non-specific characters from string by number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Stripping-non-specific-characters-from-string-by-number/m-p/963073#M375261</link>
      <description>&lt;P&gt;You don't need to "strip" any of the characters from the string to convert it into a datetime value.&amp;nbsp; To ignore the milliseconds just use an INFORMAT with a width of only 19 and it will only read the first 19 bytes of the string.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Of use a wider width and read in the milliseconds.&amp;nbsp; Then you can decide if you want to keep them in the value and set the format to not display them.&amp;nbsp; Or remove them by either truncating to an integer, or rounding to an integer.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  actual_datetime = input(start_datetime,anydtdtm19.);
  format actual_datetime datetime19.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;Obs        Start_Datetime             actual_datetime

 1     2022-06-26 19:43:00.358     26JUN2022:19:43:00
 2     2022-06-26 21:33:13.403     26JUN2022:21:33:13
 3     2022-08-30 07:26:04.178     30AUG2022:07:26:04
&lt;/PRE&gt;</description>
      <pubDate>Tue, 01 Apr 2025 02:22:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Stripping-non-specific-characters-from-string-by-number/m-p/963073#M375261</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-04-01T02:22:34Z</dc:date>
    </item>
  </channel>
</rss>

