<?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 extract an information from a string and creating new variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-information-from-a-string-and-creating-new/m-p/500373#M133252</link>
    <description>&lt;P&gt;So there must be a file definition then, or is this just an empty Notepad file which they type into?&lt;/P&gt;</description>
    <pubDate>Mon, 01 Oct 2018 13:51:19 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2018-10-01T13:51:19Z</dc:date>
    <item>
      <title>How to extract an information from a string and creating new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-information-from-a-string-and-creating-new/m-p/500339#M133228</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a&amp;nbsp;string variable like below&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Blood Transfusion Results 08/24/2018 04:21 Hemoglobin 6.9 gm/dL 08/24/2018 01:29 BG-Lactate 1.33 mmol/L 08/24/2018 07:00 Systolic BP 101 mmHg 08/24/2018 07:00 Heart Rate 95 bpm&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to create columns for Hemoglobin (value 6.9), Lactate (value 1.33), Systolic BP (101), and Heart rate (95). How can I do this. Please help!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, I was trying to write dataline for this but it was not working out, I was getting truncated data. It will be another question that I will post to get the answer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you all.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Oct 2018 13:04:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-information-from-a-string-and-creating-new/m-p/500339#M133228</guid>
      <dc:creator>AMFR</dc:creator>
      <dc:date>2018-10-01T13:04:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract an information from a string and creating new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-information-from-a-string-and-creating-new/m-p/500362#M133245</link>
      <description>&lt;P&gt;Why do you have a string like that in the first place?&amp;nbsp; Is this from a file?&amp;nbsp; Is there some sort of data description for the file?&amp;nbsp; Can the file be more completely descriptive so post processing not be necessary?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From what you have there you will need to do some sort of substr(your string,findw("Haemaglobin")+12,next space).&lt;/P&gt;
&lt;P&gt;Which is a bit of a mess and prone to issues.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Oct 2018 13:45:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-information-from-a-string-and-creating-new/m-p/500362#M133245</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-10-01T13:45:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract an information from a string and creating new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-information-from-a-string-and-creating-new/m-p/500365#M133247</link>
      <description>&lt;P&gt;This is coming from power chart providers use at hospital&lt;/P&gt;</description>
      <pubDate>Mon, 01 Oct 2018 13:47:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-information-from-a-string-and-creating-new/m-p/500365#M133247</guid>
      <dc:creator>AMFR</dc:creator>
      <dc:date>2018-10-01T13:47:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract an information from a string and creating new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-information-from-a-string-and-creating-new/m-p/500373#M133252</link>
      <description>&lt;P&gt;So there must be a file definition then, or is this just an empty Notepad file which they type into?&lt;/P&gt;</description>
      <pubDate>Mon, 01 Oct 2018 13:51:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-information-from-a-string-and-creating-new/m-p/500373#M133252</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-10-01T13:51:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract an information from a string and creating new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-information-from-a-string-and-creating-new/m-p/500378#M133254</link>
      <description>&lt;P&gt;I honestly don't know about file definition, we have a big data warehouse where I pull data from. Below are codes for 2 of the patients I have in my data, can you please look into this and help me. I am trying with substr but no result&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New"&gt;data&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New"&gt; work.transfuse;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;infile&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; datalines &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;delimiter&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New"&gt;","&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;length&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; Type $&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New"&gt;100&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New"&gt; Result $&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New"&gt;500&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; Encounter Type $ Result $;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1240,Blood Transfusion Reason,Anemia&lt;/P&gt;&lt;P&gt;1240,Packed RBC Transfusion Template,Blood Transfusion Results 08/24/2018 04:21 Hemoglobin 6.9 gm/dL 08/24/2018 01:29 BG-Lactate 1.33 mmol/L 08/24/2018 07:00 Systolic BP 101 mmHg 08/24/2018 07:00 Heart Rate 95 bpm&lt;/P&gt;&lt;P&gt;1240,Transfusion Indications Hemoglobin,Hemoglobin [Hgb] &amp;lt; 8gm/dL&lt;/P&gt;&lt;P&gt;1250,Blood Transfusion Reason,Anemia&lt;/P&gt;&lt;P&gt;1250,Packed RBC Transfusion Template,Blood Transfusion Results 08/22/2018 12:00 Systolic BP 120 mmHg 08/22/2018 12:00 Heart Rate 67 bpm&lt;/P&gt;&lt;P&gt;1250,Transfusion Indications Hemoglobin,Hemoglobin [Hgb] &amp;lt; 8gm/dL&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New"&gt;print&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New"&gt;data&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;=work.transfuse;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Oct 2018 13:55:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-information-from-a-string-and-creating-new/m-p/500378#M133254</guid>
      <dc:creator>AMFR</dc:creator>
      <dc:date>2018-10-01T13:55:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract an information from a string and creating new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-information-from-a-string-and-creating-new/m-p/500406#M133272</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines delimiter=",";
length Type $100 Result $500;
input Encounter Type $ Result $;
datalines;
1240,Blood Transfusion Reason,Anemia
1240,Packed RBC Transfusion Template,Blood Transfusion Results 08/24/2018 04:21 Hemoglobin 6.9 gm/dL 08/24/2018 01:29 BG-Lactate 1.33 mmol/L 08/24/2018 07:00 Systolic BP 101 mmHg 08/24/2018 07:00 Heart Rate 95 bpm
1240,Transfusion Indications Hemoglobin,Hemoglobin [Hgb] &amp;lt; 8gm/dL
1250,Blood Transfusion Reason,Anemia
1250,Packed RBC Transfusion Template,Blood Transfusion Results 08/22/2018 12:00 Systolic BP 120 mmHg 08/22/2018 12:00 Heart Rate 67 bpm
1250,Transfusion Indications Hemoglobin,Hemoglobin [Hgb] &amp;lt; 8gm/dL
;

run;

data want;
set have;
length string2 $200.;

/* We add a field separator */
string2=prxchange("s/([0-9\/]* [0-9]{2}:[0-9]{2})/@/",-1,result);

/* The field separator is used to isolate and output each element */
if result=:"Blood" then do i=2 to countw(string2,'@');
    element=scan(string2,i,'@');
    V1=prxchange("s/([^\d]*).*$/$1/",1,element);
	V2=input(prxchange("s/[^\d]*([\d.]*).*$/$1/",1,element), best.);
	output;
end;

keep Encounter V1 V2;
run;

proc transpose data=want out=want2;
    by Encounter;
    var V2;
    id V1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Edit: removed tranwrd ans strip as proc transpose transforms values into valid column names.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Oct 2018 14:34:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-information-from-a-string-and-creating-new/m-p/500406#M133272</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2018-10-01T14:34:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract an information from a string and creating new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-information-from-a-string-and-creating-new/m-p/500665#M133364</link>
      <description>&lt;P&gt;Thank you!!&lt;/P&gt;</description>
      <pubDate>Tue, 02 Oct 2018 10:41:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-an-information-from-a-string-and-creating-new/m-p/500665#M133364</guid>
      <dc:creator>AMFR</dc:creator>
      <dc:date>2018-10-02T10:41:11Z</dc:date>
    </item>
  </channel>
</rss>

