<?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 Extract the values from the text for calculation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Extract-the-values-from-the-text-for-calculation/m-p/746472#M234172</link>
    <description>&lt;P&gt;I need to extract the value of drug dosage given in the Morning, Afternoon and Night for the calculation from the scratch set.&lt;/P&gt;
&lt;P&gt;Here I given the sample dataset and expected output for your reference.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Drugs&amp;amp;$500.;
cards;
Variable_Dose Unit MORNING(V) x90 days Morning 28 unit, Afternoon 0 unit, Night 0 unit
Variable_Dose Unit MORNING(V) , Morning 20 unit, ,
(Mor-Aft) , Morning 15 unit, Afternoon 12 unit, Morning 16 unit, Afternoon 10 unit,
(Mor-Aft) , Morning 015 unit Afternoon 10 unit
(Mor-Aft) , Morning 0 unit, Afternoon 0 unit, Night 15 unit, , , Night 15 unit
(N) , Night 10 unit LAST DOST&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Expected Output:&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 144pt;" border="0" width="192" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" style="height: 15.0pt; width: 48pt;"&gt;Morning&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;Afternoon&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;Night&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;28&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;20&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;31&lt;/TD&gt;
&lt;TD align="right"&gt;32&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;15&lt;/TD&gt;
&lt;TD align="right"&gt;10&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;0&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD align="right"&gt;30&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD align="right"&gt;10&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;(or)&lt;/P&gt;
&lt;P&gt;If it a huge process to SUM the unit values, at-least help me to extract the keyword like below as output:&lt;/P&gt;
&lt;TABLE width="527"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="129px" height="30px"&gt;Col1&lt;/TD&gt;
&lt;TD width="137px" height="30px"&gt;Col2&lt;/TD&gt;
&lt;TD width="123px" height="30px"&gt;Col3&lt;/TD&gt;
&lt;TD width="137px" height="30px"&gt;Col4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="129px" height="30px"&gt;Morning 28 unit&lt;/TD&gt;
&lt;TD width="137px" height="30px"&gt;Afternoon 0 unit&lt;/TD&gt;
&lt;TD width="123px" height="30px"&gt;Night 0 unit&lt;/TD&gt;
&lt;TD width="137px" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="129px" height="30px"&gt;Morning 20 unit&lt;/TD&gt;
&lt;TD width="137px" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="123px" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="137px" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="129px" height="30px"&gt;Morning 15 unit&lt;/TD&gt;
&lt;TD width="137px" height="30px"&gt;Afternoon 12 unit&lt;/TD&gt;
&lt;TD width="123px" height="30px"&gt;Morning 16 unit&lt;/TD&gt;
&lt;TD width="137px" height="30px"&gt;Afternoon 10 unit&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="129px" height="57px"&gt;Morning 015 unit&lt;/TD&gt;
&lt;TD width="137px" height="57px"&gt;Afternoon 10 unit&lt;/TD&gt;
&lt;TD width="123px" height="57px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="137px" height="57px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="129px" height="30px"&gt;Morning 0 unit&lt;/TD&gt;
&lt;TD width="137px" height="30px"&gt;Afternoon 0 unit&lt;/TD&gt;
&lt;TD width="123px" height="30px"&gt;Night 15 unit&lt;/TD&gt;
&lt;TD width="137px" height="30px"&gt;Night 15 unit&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="129px" height="30px"&gt;Night 10 unit&lt;/TD&gt;
&lt;TD width="137px" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="123px" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="137px" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The extraction process should be done with in the Keyword/Syntax : Day Value Unit&lt;/P&gt;
&lt;P&gt;Any help will be appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 08 Jun 2021 16:01:13 GMT</pubDate>
    <dc:creator>Sathish_jammy</dc:creator>
    <dc:date>2021-06-08T16:01:13Z</dc:date>
    <item>
      <title>Extract the values from the text for calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-the-values-from-the-text-for-calculation/m-p/746472#M234172</link>
      <description>&lt;P&gt;I need to extract the value of drug dosage given in the Morning, Afternoon and Night for the calculation from the scratch set.&lt;/P&gt;
&lt;P&gt;Here I given the sample dataset and expected output for your reference.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Drugs&amp;amp;$500.;
cards;
Variable_Dose Unit MORNING(V) x90 days Morning 28 unit, Afternoon 0 unit, Night 0 unit
Variable_Dose Unit MORNING(V) , Morning 20 unit, ,
(Mor-Aft) , Morning 15 unit, Afternoon 12 unit, Morning 16 unit, Afternoon 10 unit,
(Mor-Aft) , Morning 015 unit Afternoon 10 unit
(Mor-Aft) , Morning 0 unit, Afternoon 0 unit, Night 15 unit, , , Night 15 unit
(N) , Night 10 unit LAST DOST&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Expected Output:&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 144pt;" border="0" width="192" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" style="height: 15.0pt; width: 48pt;"&gt;Morning&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;Afternoon&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;Night&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;28&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;20&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;31&lt;/TD&gt;
&lt;TD align="right"&gt;32&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;15&lt;/TD&gt;
&lt;TD align="right"&gt;10&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;0&lt;/TD&gt;
&lt;TD align="right"&gt;0&lt;/TD&gt;
&lt;TD align="right"&gt;30&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD align="right"&gt;10&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;(or)&lt;/P&gt;
&lt;P&gt;If it a huge process to SUM the unit values, at-least help me to extract the keyword like below as output:&lt;/P&gt;
&lt;TABLE width="527"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="129px" height="30px"&gt;Col1&lt;/TD&gt;
&lt;TD width="137px" height="30px"&gt;Col2&lt;/TD&gt;
&lt;TD width="123px" height="30px"&gt;Col3&lt;/TD&gt;
&lt;TD width="137px" height="30px"&gt;Col4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="129px" height="30px"&gt;Morning 28 unit&lt;/TD&gt;
&lt;TD width="137px" height="30px"&gt;Afternoon 0 unit&lt;/TD&gt;
&lt;TD width="123px" height="30px"&gt;Night 0 unit&lt;/TD&gt;
&lt;TD width="137px" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="129px" height="30px"&gt;Morning 20 unit&lt;/TD&gt;
&lt;TD width="137px" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="123px" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="137px" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="129px" height="30px"&gt;Morning 15 unit&lt;/TD&gt;
&lt;TD width="137px" height="30px"&gt;Afternoon 12 unit&lt;/TD&gt;
&lt;TD width="123px" height="30px"&gt;Morning 16 unit&lt;/TD&gt;
&lt;TD width="137px" height="30px"&gt;Afternoon 10 unit&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="129px" height="57px"&gt;Morning 015 unit&lt;/TD&gt;
&lt;TD width="137px" height="57px"&gt;Afternoon 10 unit&lt;/TD&gt;
&lt;TD width="123px" height="57px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="137px" height="57px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="129px" height="30px"&gt;Morning 0 unit&lt;/TD&gt;
&lt;TD width="137px" height="30px"&gt;Afternoon 0 unit&lt;/TD&gt;
&lt;TD width="123px" height="30px"&gt;Night 15 unit&lt;/TD&gt;
&lt;TD width="137px" height="30px"&gt;Night 15 unit&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="129px" height="30px"&gt;Night 10 unit&lt;/TD&gt;
&lt;TD width="137px" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="123px" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="137px" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The extraction process should be done with in the Keyword/Syntax : Day Value Unit&lt;/P&gt;
&lt;P&gt;Any help will be appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jun 2021 16:01:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-the-values-from-the-text-for-calculation/m-p/746472#M234172</guid>
      <dc:creator>Sathish_jammy</dc:creator>
      <dc:date>2021-06-08T16:01:13Z</dc:date>
    </item>
    <item>
      <title>Re: Extract the values from the text for calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-the-values-from-the-text-for-calculation/m-p/746478#M234175</link>
      <description>&lt;P&gt;Is one of the rules that you &lt;STRONG&gt;did not state&lt;/STRONG&gt; that when a record has multiples of morning, afternoon or night that they are SUMMED?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any other rule(s) not stated?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jun 2021 14:46:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-the-values-from-the-text-for-calculation/m-p/746478#M234175</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-06-08T14:46:48Z</dc:date>
    </item>
    <item>
      <title>Re: Extract the values from the text for calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-the-values-from-the-text-for-calculation/m-p/746483#M234179</link>
      <description>I apologize for not stating that point, There is no other rule need to be stated.&lt;BR /&gt;Thank you for your response &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;</description>
      <pubDate>Tue, 08 Jun 2021 14:56:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-the-values-from-the-text-for-calculation/m-p/746483#M234179</guid>
      <dc:creator>Sathish_jammy</dc:creator>
      <dc:date>2021-06-08T14:56:15Z</dc:date>
    </item>
    <item>
      <title>Re: Extract the values from the text for calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-the-values-from-the-text-for-calculation/m-p/746511#M234190</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/215282"&gt;@Sathish_jammy&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is one way to solve the problem. The principle is to scan the string for words separated by blanks. If a keyword (Morning, Afternoon, Night) is found, the next "word" is added as value to the corresponding sum variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Drugs&amp;amp;$500.;
cards;
Variable_Dose Unit MORNING(V) x90 days Morning 28 unit, Afternoon 0 unit, Night 0 unit
Variable_Dose Unit MORNING(V) , Morning 20 unit, ,
(Mor-Aft) , Morning 15 unit, Afternoon 12 unit, Morning 16 unit, Afternoon 10 unit,
(Mor-Aft) , Morning 015 unit Afternoon 10 unit
(Mor-Aft) , Morning 0 unit, Afternoon 0 unit, Night 15 unit, , , Night 15 unit
(N) , Night 10 unit LAST DOST
;
run;

data want(drop=Drugs tmpstr i); 
	set have;
	length tmpstr $20;
	call missing (of Morning Afternoon Night);
	do i = 1 to countw(Drugs,' ')-1;
		tmpstr = scan(Drugs,i,' ');
		if tmpstr = 'Morning' then Morning + input(scan(Drugs,i+1,' '),??8.);
		else if tmpstr = 'Afternoon' then Afternoon + input(scan(Drugs,i+1,' '),??8.);
		else if tmpstr = 'Night' then Night + input(scan(Drugs,i+1,' '),??8.);
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jun 2021 16:57:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-the-values-from-the-text-for-calculation/m-p/746511#M234190</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2021-06-08T16:57:47Z</dc:date>
    </item>
    <item>
      <title>Re: Extract the values from the text for calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-the-values-from-the-text-for-calculation/m-p/746734#M234286</link>
      <description>&lt;PRE&gt;data have;
input Drugs&amp;amp;$500.;
cards;
Variable_Dose Unit MORNING(V) x90 days Morning 28 unit, Afternoon 0 unit, Night 0 unit
Variable_Dose Unit MORNING(V) , Morning 20 unit, ,
(Mor-Aft) , Morning 15 unit, Afternoon 12 unit, Morning 16 unit, Afternoon 10 unit,
(Mor-Aft) , Morning 015 unit Afternoon 10 unit
(Mor-Aft) , Morning 0 unit, Afternoon 0 unit, Night 15 unit, , , Night 15 unit
(N) , Night 10 unit LAST DOST
;
run;
data temp;
 set have;
 count=_n_;
 pid=prxparse('/\w+\s+\d+\s+unit\b/i');
 s=1;e=length(drugs);
 call prxnext(pid,s,e,drugs,p,l);
 do while(p&amp;gt;0);
   var=substr(drugs,p,l);
   call prxnext(pid,s,e,drugs,p,l);
   output;
 end;
 drop pid s  e p l ;
 run;
 proc transpose data=temp out=want;
 by count drugs;
 var var;
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 Jun 2021 13:29:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-the-values-from-the-text-for-calculation/m-p/746734#M234286</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-06-09T13:29:06Z</dc:date>
    </item>
  </channel>
</rss>

