<?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: Precisely connect substrings of dates in one field to substrings of events in another field in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Precisely-connect-substrings-of-dates-in-one-field-to-substrings/m-p/917749#M361521</link>
    <description>&lt;P&gt;I downloaded your SAS dataset and looked at it with SAS Universal Viewer.&amp;nbsp; Both of your variables, EVENT_DATE and EVENT_TYPE, actually do have delimiters, but they aren't displayed when seen in the viewer. The delimiters are, in hexadecimal, 0D0A (control characters for carriage return/line feed).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You probably have a single Excel cell with multiple lines in it (one line per date).&amp;nbsp; That is a self-defeating way of storing data.&amp;nbsp; You can, however, use the 0D0A as boundaries:&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data want (drop=_: event_date event_type);
  set pp_obs;
  length _string1 _string2 $500 ;
  _string1=event_date;
  _string2=left(event_type);

  do until (_string1=' ');
    date=input(substr(_string1,1,10),yymmdd10.);
    format date yymmdd10.;
    _string1=substr(_string1,13);    * Shift left by 12 characters *;
    length event $40;
    event=scan(_string2,1,'0D'x);    * Take everything preceding '0D0A'x *;
    _string2=left(substr(_string2,indexc(_string2,'0A'x)+1));  *Shift left past first '0D0A'x *;
    output;
  end;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This program assumes EVENT_DATE and EVENT_TYPE have the same number of 0D0A control character pairs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edited addition:&amp;nbsp; The SAS universal viewer was used just to confirm the download was an actual SAS data set. It did not display the 0D0A.&amp;nbsp; I ran a DATA step to show the underlying hex codes.&lt;/P&gt;</description>
    <pubDate>Sun, 25 Feb 2024 03:52:37 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2024-02-25T03:52:37Z</dc:date>
    <item>
      <title>Precisely connect substrings of dates in one field to substrings of events in another field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Precisely-connect-substrings-of-dates-in-one-field-to-substrings/m-p/917744#M361519</link>
      <description>&lt;P&gt;Hi SAS Friends,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Am working with a dataset where each field in an "Event Dates" column contains multiple dates in a string with no delimiter.&amp;nbsp; Each date connects to an "EVENT" in an adjacent column and field.&amp;nbsp; Like the dates, there are multiple events in each field and no obvious delimiter.&amp;nbsp;&lt;/P&gt;&lt;P&gt;A&amp;nbsp; sample SAS data file is attached.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The dates and events are in the correct order and sequence within their fields and when looking at them on a screen in EXCEL (the source file) they line up perfectly.&amp;nbsp; I don't have the data in any other format, unfortunately.&amp;nbsp;&lt;/P&gt;&lt;P&gt;In SAS, the dates become a single string, all with the same format (YYYY/MM/DD) .&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Need to create one row per Drug_Name, Date, Event combination, that looks like this:&lt;/P&gt;&lt;P&gt;Drug_1 2014/02/20 Withdrawn from Market&lt;BR /&gt;Drug_1 2004/12/13 License Discontinued&lt;BR /&gt;Drug_1 2003/07/31 First Launch&lt;BR /&gt;Drug_1 2003/06/30 First Approval&lt;BR /&gt;Drug_1 2003/02/24 Orphan Drug Status Granted&lt;BR /&gt;Drug_1 2001/11/29 New Disease&lt;BR /&gt;Drug_1 2001/10/29 New Licensee&lt;BR /&gt;Drug_1 2000/10/01 New Licensing Opportunity&lt;BR /&gt;Drug_1 1999/06/30 First Filing&lt;BR /&gt;Drug_1 1999/01/15 New Licensee&lt;BR /&gt;Drug_1 1998/09/15 Nonproprietary Name Granted&lt;BR /&gt;Drug_1 1998/02/15 New Licensing Opportunity&lt;BR /&gt;Drug_1 1996/11/15 Global Status Advance&lt;BR /&gt;Drug_1 1995/07/15 Drug Added&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any and all suggestions are greatly appreciated.&lt;/P&gt;&lt;P&gt;Am using SAS ver. 9.4.&lt;/P&gt;&lt;P&gt;Thank you !&lt;/P&gt;&lt;P&gt;R.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 25 Feb 2024 00:48:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Precisely-connect-substrings-of-dates-in-one-field-to-substrings/m-p/917744#M361519</guid>
      <dc:creator>rmacarthur</dc:creator>
      <dc:date>2024-02-25T00:48:18Z</dc:date>
    </item>
    <item>
      <title>Re: Precisely connect substrings of dates in one field to substrings of events in another field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Precisely-connect-substrings-of-dates-in-one-field-to-substrings/m-p/917749#M361521</link>
      <description>&lt;P&gt;I downloaded your SAS dataset and looked at it with SAS Universal Viewer.&amp;nbsp; Both of your variables, EVENT_DATE and EVENT_TYPE, actually do have delimiters, but they aren't displayed when seen in the viewer. The delimiters are, in hexadecimal, 0D0A (control characters for carriage return/line feed).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You probably have a single Excel cell with multiple lines in it (one line per date).&amp;nbsp; That is a self-defeating way of storing data.&amp;nbsp; You can, however, use the 0D0A as boundaries:&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data want (drop=_: event_date event_type);
  set pp_obs;
  length _string1 _string2 $500 ;
  _string1=event_date;
  _string2=left(event_type);

  do until (_string1=' ');
    date=input(substr(_string1,1,10),yymmdd10.);
    format date yymmdd10.;
    _string1=substr(_string1,13);    * Shift left by 12 characters *;
    length event $40;
    event=scan(_string2,1,'0D'x);    * Take everything preceding '0D0A'x *;
    _string2=left(substr(_string2,indexc(_string2,'0A'x)+1));  *Shift left past first '0D0A'x *;
    output;
  end;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This program assumes EVENT_DATE and EVENT_TYPE have the same number of 0D0A control character pairs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edited addition:&amp;nbsp; The SAS universal viewer was used just to confirm the download was an actual SAS data set. It did not display the 0D0A.&amp;nbsp; I ran a DATA step to show the underlying hex codes.&lt;/P&gt;</description>
      <pubDate>Sun, 25 Feb 2024 03:52:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Precisely-connect-substrings-of-dates-in-one-field-to-substrings/m-p/917749#M361521</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-02-25T03:52:37Z</dc:date>
    </item>
    <item>
      <title>Re: Precisely connect substrings of dates in one field to substrings of events in another field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Precisely-connect-substrings-of-dates-in-one-field-to-substrings/m-p/917750#M361522</link>
      <description>&lt;P&gt;This is excellent and works like a charm, thank you.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I did not know that SAS Universal Viewer can help identify ODOA characters.&lt;/P&gt;&lt;P&gt;I've learned a great deal from your approach,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again,&amp;nbsp;&lt;/P&gt;&lt;P&gt;R.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 25 Feb 2024 03:33:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Precisely-connect-substrings-of-dates-in-one-field-to-substrings/m-p/917750#M361522</guid>
      <dc:creator>rmacarthur</dc:creator>
      <dc:date>2024-02-25T03:33:09Z</dc:date>
    </item>
    <item>
      <title>Re: Precisely connect substrings of dates in one field to substrings of events in another field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Precisely-connect-substrings-of-dates-in-one-field-to-substrings/m-p/917751#M361523</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/28361"&gt;@rmacarthur&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;This is excellent and works like a charm, thank you.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I did not know that SAS Universal Viewer can help identify ODOA characters.&lt;/P&gt;
&lt;P&gt;I've learned a great deal from your approach,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks again,&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Sorry to mislead, but as far as I know SAS Universal Viewer does NOT help identify 0D0A characters.&amp;nbsp; I just used it first to make sure the file was an actual SAS data set (I don't usually download SAS datasets from SAS Communities).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It looked real, so then I ran a SAS DATA step, and displayed each character in event_type and event_date in ascii characters, and and the corresponding hex code.&amp;nbsp; That's where I saw the otherwise undisplayed carriage return/line feed characters.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 25 Feb 2024 03:50:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Precisely-connect-substrings-of-dates-in-one-field-to-substrings/m-p/917751#M361523</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-02-25T03:50:57Z</dc:date>
    </item>
    <item>
      <title>Re: Precisely connect substrings of dates in one field to substrings of events in another field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Precisely-connect-substrings-of-dates-in-one-field-to-substrings/m-p/917771#M361528</link>
      <description>&lt;P&gt;One part of getting to Know Your Data (Maxim 3) is using the $HEX format for character variables to make everything contained in a string visible. It lets you see control characters like CR and LF, and you can identify single-byte characters vs. UTF.&lt;/P&gt;</description>
      <pubDate>Sun, 25 Feb 2024 08:31:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Precisely-connect-substrings-of-dates-in-one-field-to-substrings/m-p/917771#M361528</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-02-25T08:31:56Z</dc:date>
    </item>
    <item>
      <title>Re: Precisely connect substrings of dates in one field to substrings of events in another field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Precisely-connect-substrings-of-dates-in-one-field-to-substrings/m-p/917828#M361539</link>
      <description>&lt;P&gt;Thanks very much for clarifying, this is very helpful too, and am looking up how to identify ASCI characters in a data step, now.&amp;nbsp; They can certainly reek havoc!&lt;/P&gt;&lt;P&gt;Much Appreciated,&amp;nbsp;&lt;/P&gt;&lt;P&gt;R.&lt;/P&gt;</description>
      <pubDate>Sun, 25 Feb 2024 19:26:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Precisely-connect-substrings-of-dates-in-one-field-to-substrings/m-p/917828#M361539</guid>
      <dc:creator>rmacarthur</dc:creator>
      <dc:date>2024-02-25T19:26:21Z</dc:date>
    </item>
    <item>
      <title>Re: Precisely connect substrings of dates in one field to substrings of events in another field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Precisely-connect-substrings-of-dates-in-one-field-to-substrings/m-p/917830#M361540</link>
      <description>&lt;P&gt;Hi Kurt,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks, I found an earlier comment from you where you recommend, &lt;EM&gt;"Use the&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/lefunctionsref/p0m5k2s76pmv9pn1n1lu3vfyq8s4.htm" target="_blank" rel="noopener nofollow noreferrer"&gt;RANK Function&lt;/A&gt;&amp;nbsp;to get the ASCII code, and the&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/lefunctionsref/n1jfxetjdn0nxan1w4e64c7rouz9.htm" target="_blank" rel="noopener nofollow noreferrer"&gt;BYTE Function&lt;/A&gt;&lt;/EM&gt;&lt;SPAN&gt;&lt;EM&gt;&amp;nbsp;to get the character from the code.".&lt;/EM&gt;&amp;nbsp; I'll add &lt;EM&gt;"learn how to use $HEX format"&lt;/EM&gt;, and will look into all three.&amp;nbsp; BC the datasets am using at the moment are full of 'hidden characters' and they have thrown monkey wrenches into past analyses, resulting in much wasted time.&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;BTW am a big fan of the 'Maxims' !&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks !&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;R.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 25 Feb 2024 19:40:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Precisely-connect-substrings-of-dates-in-one-field-to-substrings/m-p/917830#M361540</guid>
      <dc:creator>rmacarthur</dc:creator>
      <dc:date>2024-02-25T19:40:55Z</dc:date>
    </item>
  </channel>
</rss>

