<?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: Copying the values from SAS variable, a whole column as text into a data step in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Copying-the-values-from-SAS-variable-a-whole-column-as-text-into/m-p/474894#M285949</link>
    <description>&lt;P&gt;It is very difficulty ,you need consider&amp;nbsp; all the pattern of DATE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards truncover;
input id $ reason $80.;
cards;
1)  Multiple calls 14May2018, 15May2018, 16May2018, 17May2018, 18May2018.
2)  No contact made, participant had surgery on 20 Oct 2017
3)  No response
4)  no answer  18-19Jan18
5)  no info not contactable 16/11/17
;
run;

data want;
 set have;
 pid=prxparse('/\d+\s*[a-z]{3}\s*\d{2,}|\d+\-\d+[a-z]{3}\d+|\d+\/\d+\/\d+/i');
 s=1;
 e=length(reason);
 call prxnext(pid,s,e,reason,p,l);
 do while(p&amp;gt;0);
   want=substr(reason,p,l);output;
   call prxnext(pid,s,e,reason,p,l);
 end;
 drop s e pid p l;
run;

proc print noobs;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 02 Jul 2018 13:25:58 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2018-07-02T13:25:58Z</dc:date>
    <item>
      <title>Copying the values from SAS variable, a whole column as text into a data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Copying-the-values-from-SAS-variable-a-whole-column-as-text-into/m-p/474795#M285945</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a dataset with 2 variables, id and reason. the dataset has&amp;nbsp;240 rows. The issue I have is that the variable reason has date values in it but those values are not consistent in format:&lt;/P&gt;
&lt;P&gt;e.g&amp;nbsp; HAVE&lt;/P&gt;
&lt;P&gt;ID&amp;nbsp;&amp;nbsp; REASON&lt;/P&gt;
&lt;P&gt;1) Multiple&amp;nbsp;calls 14May2018, 15May2018, 16May2018, 17May2018, 18May2018.&lt;/P&gt;
&lt;P&gt;2) No contact made, participant had surgery on 20 Oct 2017&lt;/P&gt;
&lt;P&gt;3) No response&lt;/P&gt;
&lt;P&gt;4) no answer &amp;nbsp;18-19Jan18&lt;/P&gt;
&lt;P&gt;5) no info not contactable 16/11/17.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to create a third variable and extract the date from the variable "reason" when available.&lt;/P&gt;
&lt;P&gt;WANT&lt;/P&gt;
&lt;P&gt;1)14May2018&lt;/P&gt;
&lt;P&gt;1)15May2018&lt;/P&gt;
&lt;P&gt;1)16May2018&lt;/P&gt;
&lt;P&gt;1)17May2018&lt;/P&gt;
&lt;P&gt;1)18May2018&lt;/P&gt;
&lt;P&gt;2)20Oct17&lt;/P&gt;
&lt;P&gt;3)&lt;/P&gt;
&lt;P&gt;4)18Jan2018&lt;/P&gt;
&lt;P&gt;4)19Jan2018&lt;/P&gt;
&lt;P&gt;5)16Nov2017.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if there a way to copy&amp;nbsp; the content of the 240 rows of the variable reason in a subsequent data step in order to extract the date and assign he dates into a new variable date.&amp;nbsp;The issue I am having sis that the dates are not in an identical format sometimes it is 16/11/17 , sometimes 12 dec, other times 18-19 jan&lt;/P&gt;</description>
      <pubDate>Sun, 01 Jul 2018 23:09:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Copying-the-values-from-SAS-variable-a-whole-column-as-text-into/m-p/474795#M285945</guid>
      <dc:creator>Kc2</dc:creator>
      <dc:date>2018-07-01T23:09:16Z</dc:date>
    </item>
    <item>
      <title>Re: Coying the values from SAS variable, a whole column as text into a data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Copying-the-values-from-SAS-variable-a-whole-column-as-text-into/m-p/474799#M285946</link>
      <description>&lt;P&gt;i don't understand your final sentence ie your Q. You just have to write code eg substr and index functions to extract the date data and then derive the new date variable&lt;/P&gt;</description>
      <pubDate>Sun, 01 Jul 2018 22:37:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Copying-the-values-from-SAS-variable-a-whole-column-as-text-into/m-p/474799#M285946</guid>
      <dc:creator>pau13rown</dc:creator>
      <dc:date>2018-07-01T22:37:23Z</dc:date>
    </item>
    <item>
      <title>Re: Copying the values from SAS variable, a whole column as text into a data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Copying-the-values-from-SAS-variable-a-whole-column-as-text-into/m-p/474812#M285947</link>
      <description>&lt;P&gt;There isn’t an automated method to do this. For 240 records I’d almost consider doing it manually, probably about an hour worth of work.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To do it programming - which is better in the long run - first isolate all your different type of entry.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Handle the simplest first and work through them.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use SCAN to isolate each word in the statement and then test if it’s a date using INPUT() with the ANYDTE informat. That’ll probably take care of most of your cases.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PROC FREQ, and text functions will be useful.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Find, index, translate, compress, substr, scan, countw are some that you’ll need.&amp;nbsp;&lt;/P&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/3443"&gt;@Kc2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a dataset with 2 variables, id and reason. the dataset has&amp;nbsp;240 rows. The issue I have is that the variable reason has date values in it but those values are not consistent in format:&lt;/P&gt;
&lt;P&gt;e.g&amp;nbsp; HAVE&lt;/P&gt;
&lt;P&gt;ID&amp;nbsp;&amp;nbsp; REASON&lt;/P&gt;
&lt;P&gt;1) Multiple&amp;nbsp;calls 14May2018, 15May2018, 16May2018, 17May2018, 18May2018.&lt;/P&gt;
&lt;P&gt;2) No contact made, participant had surgery on 20 Oct 2017&lt;/P&gt;
&lt;P&gt;3) No response&lt;/P&gt;
&lt;P&gt;4) no answer &amp;nbsp;18-19Jan18&lt;/P&gt;
&lt;P&gt;5) no info not contactable 16/11/17.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to create a third variable and extract the date from the variable "reason" when available.&lt;/P&gt;
&lt;P&gt;WANT&lt;/P&gt;
&lt;P&gt;1)14May2018&lt;/P&gt;
&lt;P&gt;1)15May2018&lt;/P&gt;
&lt;P&gt;1)16May2018&lt;/P&gt;
&lt;P&gt;1)17May2018&lt;/P&gt;
&lt;P&gt;1)18May2018&lt;/P&gt;
&lt;P&gt;2)20Oct17&lt;/P&gt;
&lt;P&gt;3)&lt;/P&gt;
&lt;P&gt;4)18Jan2018&lt;/P&gt;
&lt;P&gt;4)19Jan2018&lt;/P&gt;
&lt;P&gt;5)16Nov2017.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if there a way to copy&amp;nbsp; the content of the 240 rows of the variable reason in a subsequent data step in order to extract the date and assign he dates into a new variable date.&amp;nbsp;The issue I am having sis that the dates are not in an identical format sometimes it is 16/11/17 , sometimes 12 dec, other times 18-19 jan&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Jul 2018 04:16:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Copying-the-values-from-SAS-variable-a-whole-column-as-text-into/m-p/474812#M285947</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-07-02T04:16:03Z</dc:date>
    </item>
    <item>
      <title>Re: Copying the values from SAS variable, a whole column as text into a data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Copying-the-values-from-SAS-variable-a-whole-column-as-text-into/m-p/474830#M285948</link>
      <description>&lt;P&gt;Manually may be the only option, consider the case:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;5) no info not contactable 08/06/17&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Is this 08Jun or 06Aug?&amp;nbsp; There are a fair few other examples out there, different formats methods of putting dates etc.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You could do some things in code:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;start=substr(reason,findc(reason,"","d"));&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;For instance would find the first numeric in the string, if they are all like your example, that would trim it down a bit.&amp;nbsp; Even so, by the time you have programmed each check, it would be quicker to do it manually.&amp;nbsp; This is why free text fields are frowned upon on stats and databasing, next to impossible to get anything useful out of it.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Jul 2018 07:39:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Copying-the-values-from-SAS-variable-a-whole-column-as-text-into/m-p/474830#M285948</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-07-02T07:39:43Z</dc:date>
    </item>
    <item>
      <title>Re: Copying the values from SAS variable, a whole column as text into a data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Copying-the-values-from-SAS-variable-a-whole-column-as-text-into/m-p/474894#M285949</link>
      <description>&lt;P&gt;It is very difficulty ,you need consider&amp;nbsp; all the pattern of DATE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards truncover;
input id $ reason $80.;
cards;
1)  Multiple calls 14May2018, 15May2018, 16May2018, 17May2018, 18May2018.
2)  No contact made, participant had surgery on 20 Oct 2017
3)  No response
4)  no answer  18-19Jan18
5)  no info not contactable 16/11/17
;
run;

data want;
 set have;
 pid=prxparse('/\d+\s*[a-z]{3}\s*\d{2,}|\d+\-\d+[a-z]{3}\d+|\d+\/\d+\/\d+/i');
 s=1;
 e=length(reason);
 call prxnext(pid,s,e,reason,p,l);
 do while(p&amp;gt;0);
   want=substr(reason,p,l);output;
   call prxnext(pid,s,e,reason,p,l);
 end;
 drop s e pid p l;
run;

proc print noobs;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 02 Jul 2018 13:25:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Copying-the-values-from-SAS-variable-a-whole-column-as-text-into/m-p/474894#M285949</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-07-02T13:25:58Z</dc:date>
    </item>
  </channel>
</rss>

