<?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: Parsing out complicated string variable into new variables in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Parsing-out-complicated-string-variable-into-new-variables/m-p/549962#M8740</link>
    <description>&lt;P&gt;See this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input invar $80.;
datalines;
Mon Mar 25 2019 17:46:55 GMT+0000 (Coordinated Universal Time)
Mon Mar 11 2019 19:27:44 GMT+0000 (Coordinated Universal Time)
Mon Mar 11 2019 19:28:29 GMT+0000 (Coordinated Universal Time)
;
run;

data want;
set have;
datestr = scan(invar,3) !! scan(invar,2) !! scan(invar,4);
dtvar = input(datestr,date9.);
timevar = input(scan(invar,5),time8.);
format dtvar date9. timevar time8.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I use invar in my example dataset as column name. If your column is named differently, just replace "invar" with your column name.&lt;/P&gt;</description>
    <pubDate>Wed, 10 Apr 2019 13:57:06 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2019-04-10T13:57:06Z</dc:date>
    <item>
      <title>Parsing out complicated string variable into new variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Parsing-out-complicated-string-variable-into-new-variables/m-p/549942#M8734</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need help parsing out this string variable into something usable:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Mon Mar 25 2019 17:46:55 GMT+0000 (Coordinated Universal Time)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I do not need anything after 17:46:55, so I only really need the Mar 25 2019 and the 17:46:55 parts of this string. I would like this conversion to be in some kind of loop, as this will need to be done &amp;gt;200 times.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!!&lt;/P&gt;</description>
      <pubDate>Wed, 10 Apr 2019 13:21:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Parsing-out-complicated-string-variable-into-new-variables/m-p/549942#M8734</guid>
      <dc:creator>fordcr2</dc:creator>
      <dc:date>2019-04-10T13:21:38Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing out complicated string variable into new variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Parsing-out-complicated-string-variable-into-new-variables/m-p/549945#M8735</link>
      <description>&lt;P&gt;A loop is required if you have multiple variables containing those strings. If you have multiple observations, you don't need to write a loop, because a data step is iterating automatically.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you post some more examples in usable form (data step with datalines)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It could be a good idea to create one datetime-variable, but this depends on the way you want to use the extracted information.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Apr 2019 13:30:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Parsing-out-complicated-string-variable-into-new-variables/m-p/549945#M8735</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-04-10T13:30:27Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing out complicated string variable into new variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Parsing-out-complicated-string-variable-into-new-variables/m-p/549946#M8736</link>
      <description>&lt;P&gt;The string can quite easily be re-assembled into a valid SAS datetime input:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input invar $80.;
datalines;
Mon Mar 25 2019 17:46:55 GMT+0000 (Coordinated Universal Time)
;
run;

data want;
set have;
dtstr = scan(invar,3) !! scan(invar,2) !! scan(invar,4) !! ':' !! scan(invar,5);
dtvar = input(dtstr,datetime19.);
format dtvar datetime19.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Apr 2019 13:32:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Parsing-out-complicated-string-variable-into-new-variables/m-p/549946#M8736</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-04-10T13:32:33Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing out complicated string variable into new variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Parsing-out-complicated-string-variable-into-new-variables/m-p/549951#M8737</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; "Some kind of loop" is a bit vague. Do you have 200 rows of data, with a date like this on each row? Or, do you have data with 200 variables or columns on each row and each of the columns is a date like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; What code have you tried? What is your end result? Do you want to have a SAS date value and a SAS time value, as 2 separate values? Do you want 2 character strings that you can display? Splitting out the information your want is fairly easy. Is there always a GMT and a + in the value; could there be a GMT and - sign in the value? Are there always parentheses in the value? Is the day of the week at the beginning always 3 characters?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Can you describe what you have and what you need in more detail?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cynthia&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Apr 2019 13:41:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Parsing-out-complicated-string-variable-into-new-variables/m-p/549951#M8737</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2019-04-10T13:41:17Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing out complicated string variable into new variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Parsing-out-complicated-string-variable-into-new-variables/m-p/549959#M8738</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I meant is that it needs to be repeatable (this is a dataset that is updated often with medical device data and there will be thousands of observations that need to be converted this way - right now there are about 200). The data comes in under the variable Regimen_Date and the observations are as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Mon Mar 25 2019 17:46:55 GMT+0000 (Coordinated Universal Time)&lt;/P&gt;&lt;P&gt;Mon Mar 11 2019 19:27:44 GMT+0000 (Coordinated Universal Time)&lt;/P&gt;&lt;P&gt;Mon Mar 11 2019 19:28:29 GMT+0000 (Coordinated Universal Time)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want the date and time to be separate variables - all of the observations come in the same format, but I would need a date variable and a time variable separately parsed out from these strings.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Apr 2019 13:51:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Parsing-out-complicated-string-variable-into-new-variables/m-p/549959#M8738</guid>
      <dc:creator>fordcr2</dc:creator>
      <dc:date>2019-04-10T13:51:50Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing out complicated string variable into new variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Parsing-out-complicated-string-variable-into-new-variables/m-p/549961#M8739</link>
      <description>&lt;P&gt;Thank you for your response. This works well, except I need the date and time variables to be separated and I need to be able to do this over and over for multiple observations under the variable name Regimen_Date.&amp;nbsp; I have very little experience with this so I am sorry if the explanation needs to be a little elementary, but is there a way to assign invar as the Regimen_Date variable I currently have?&lt;/P&gt;</description>
      <pubDate>Wed, 10 Apr 2019 13:55:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Parsing-out-complicated-string-variable-into-new-variables/m-p/549961#M8739</guid>
      <dc:creator>fordcr2</dc:creator>
      <dc:date>2019-04-10T13:55:01Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing out complicated string variable into new variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Parsing-out-complicated-string-variable-into-new-variables/m-p/549962#M8740</link>
      <description>&lt;P&gt;See this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input invar $80.;
datalines;
Mon Mar 25 2019 17:46:55 GMT+0000 (Coordinated Universal Time)
Mon Mar 11 2019 19:27:44 GMT+0000 (Coordinated Universal Time)
Mon Mar 11 2019 19:28:29 GMT+0000 (Coordinated Universal Time)
;
run;

data want;
set have;
datestr = scan(invar,3) !! scan(invar,2) !! scan(invar,4);
dtvar = input(datestr,date9.);
timevar = input(scan(invar,5),time8.);
format dtvar date9. timevar time8.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I use invar in my example dataset as column name. If your column is named differently, just replace "invar" with your column name.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Apr 2019 13:57:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Parsing-out-complicated-string-variable-into-new-variables/m-p/549962#M8740</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-04-10T13:57:06Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing out complicated string variable into new variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Parsing-out-complicated-string-variable-into-new-variables/m-p/549964#M8741</link>
      <description>&lt;P&gt;Hi thank you for the clarification. You are correct - it is just one variable with multiple observations.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The variable name is Regimen_Date and here are some more examples of what the data looks like. All observations come in in this format as well.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Mon Mar 25 2019 17:46:55 GMT+0000 (Coordinated Universal Time)&lt;/P&gt;&lt;P&gt;Mon Mar 11 2019 19:27:44 GMT+0000 (Coordinated Universal Time)&lt;/P&gt;&lt;P&gt;Mon Mar 11 2019 19:28:29 GMT+0000 (Coordinated Universal Time)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I will need a date and time variable from this (separate).&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Apr 2019 13:57:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Parsing-out-complicated-string-variable-into-new-variables/m-p/549964#M8741</guid>
      <dc:creator>fordcr2</dc:creator>
      <dc:date>2019-04-10T13:57:42Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing out complicated string variable into new variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Parsing-out-complicated-string-variable-into-new-variables/m-p/549966#M8742</link>
      <description>&lt;P&gt;That worked wonderfully! Thank you so much!&lt;/P&gt;</description>
      <pubDate>Wed, 10 Apr 2019 14:08:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Parsing-out-complicated-string-variable-into-new-variables/m-p/549966#M8742</guid>
      <dc:creator>fordcr2</dc:creator>
      <dc:date>2019-04-10T14:08:09Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing out complicated string variable into new variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Parsing-out-complicated-string-variable-into-new-variables/m-p/549996#M8746</link>
      <description>&lt;P&gt;A slightly different approach that does require a very fixed layout of the variable:&lt;/P&gt;
&lt;PRE&gt;data have;
   input invar $80.;
   dt = input (substr(invar,5,25),anydtdtm21.);
   date=datepart(dt);
   time=timepart(dt);
   format dt datetime20. date date9. time time8.;
datalines;
Mon Mar 25 2019 17:46:55 GMT+0000 (Coordinated Universal Time)
Mon Mar 11 2019 19:27:44 GMT+0000 (Coordinated Universal Time)
Mon Mar 11 2019 19:28:29 GMT+0000 (Coordinated Universal Time)
;
run;
&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Apr 2019 15:48:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Parsing-out-complicated-string-variable-into-new-variables/m-p/549996#M8746</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-04-10T15:48:54Z</dc:date>
    </item>
  </channel>
</rss>

