<?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 Parse Out Columns Based on Conditions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Parse-Out-Columns-Based-on-Conditions/m-p/954722#M372850</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to parse out the drug name, strength, and unit variable for specific medications only (Amantadine, Carbidopa, Entacapone, Apomorphine, Trihexyphenidyl, Amantadine, Trihexyphenidyl, and levodopa). The final aim is to calculate the daily dose of these medications. I have tried using the scan, compress followed by the&amp;nbsp; coalescec option to no avail.&lt;/P&gt;&lt;P&gt;1) Things to note a) Use of different delimeters "-" and "/" for the strength variable, (b) different position of drug of interest : position1/position2/position3.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have included my data and table desired.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your assistance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data WORK.HAVE;&lt;BR /&gt;infile datalines dsd truncover;&lt;BR /&gt;input Patient_ID:32. Drug_Name:$37. Strength:$12.;&lt;BR /&gt;label Patient_ID="Patient ID" Drug_Name="Drug_Name" Strength="Strength";&lt;BR /&gt;datalines;&lt;BR /&gt;1 Carbidopa 25 MG&lt;BR /&gt;1 Carbidopa/Levodopa 25-100 MG&lt;BR /&gt;2 Levodopa/Entacapone 100-200 MG&lt;BR /&gt;2 Apomorphine 2 MG/ML&lt;BR /&gt;2 Ropinirole/Entacapone 2-200 MG&lt;BR /&gt;3 Levodopa/Entacapone/Ropinirole 100-200-2 MG&lt;BR /&gt;3 Pramipexole/Entacapone/Amantadine 1-200-100 MG&lt;BR /&gt;3 Pramipexole/Trihexyphenidyl 1-2 MG&lt;BR /&gt;4 Amantadine/Benztropine 100-1 MG&lt;BR /&gt;5 Trihexyphenidyl/Rasagiline/Entacapone 2-0.5-200 MG&lt;BR /&gt;;;;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Want&lt;/STRONG&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Patient ID&lt;/TD&gt;&lt;TD&gt;Drug_of_Interest&lt;/TD&gt;&lt;TD&gt;Strength1&lt;/TD&gt;&lt;TD&gt;Unit1&lt;/TD&gt;&lt;TD&gt;Drug of interest 2&lt;/TD&gt;&lt;TD&gt;Strength2&lt;/TD&gt;&lt;TD&gt;Unit2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;Amantadine&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;MG&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;Carbidopa&lt;/TD&gt;&lt;TD&gt;25&lt;/TD&gt;&lt;TD&gt;MG&lt;/TD&gt;&lt;TD&gt;Levodopa&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;MG&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;Entacapone&lt;/TD&gt;&lt;TD&gt;200&lt;/TD&gt;&lt;T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&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;Amantadine&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;MG&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;Trihexyphenidyl&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;MG&lt;/TD&gt;&lt;TD&gt;Entacapone&lt;/TD&gt;&lt;TD&gt;200&lt;/TD&gt;&lt;TD&gt;MG&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
    <pubDate>Sun, 29 Dec 2024 10:35:26 GMT</pubDate>
    <dc:creator>cheroij</dc:creator>
    <dc:date>2024-12-29T10:35:26Z</dc:date>
    <item>
      <title>Parse Out Columns Based on Conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-Out-Columns-Based-on-Conditions/m-p/954722#M372850</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to parse out the drug name, strength, and unit variable for specific medications only (Amantadine, Carbidopa, Entacapone, Apomorphine, Trihexyphenidyl, Amantadine, Trihexyphenidyl, and levodopa). The final aim is to calculate the daily dose of these medications. I have tried using the scan, compress followed by the&amp;nbsp; coalescec option to no avail.&lt;/P&gt;&lt;P&gt;1) Things to note a) Use of different delimeters "-" and "/" for the strength variable, (b) different position of drug of interest : position1/position2/position3.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have included my data and table desired.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your assistance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data WORK.HAVE;&lt;BR /&gt;infile datalines dsd truncover;&lt;BR /&gt;input Patient_ID:32. Drug_Name:$37. Strength:$12.;&lt;BR /&gt;label Patient_ID="Patient ID" Drug_Name="Drug_Name" Strength="Strength";&lt;BR /&gt;datalines;&lt;BR /&gt;1 Carbidopa 25 MG&lt;BR /&gt;1 Carbidopa/Levodopa 25-100 MG&lt;BR /&gt;2 Levodopa/Entacapone 100-200 MG&lt;BR /&gt;2 Apomorphine 2 MG/ML&lt;BR /&gt;2 Ropinirole/Entacapone 2-200 MG&lt;BR /&gt;3 Levodopa/Entacapone/Ropinirole 100-200-2 MG&lt;BR /&gt;3 Pramipexole/Entacapone/Amantadine 1-200-100 MG&lt;BR /&gt;3 Pramipexole/Trihexyphenidyl 1-2 MG&lt;BR /&gt;4 Amantadine/Benztropine 100-1 MG&lt;BR /&gt;5 Trihexyphenidyl/Rasagiline/Entacapone 2-0.5-200 MG&lt;BR /&gt;;;;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Want&lt;/STRONG&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Patient ID&lt;/TD&gt;&lt;TD&gt;Drug_of_Interest&lt;/TD&gt;&lt;TD&gt;Strength1&lt;/TD&gt;&lt;TD&gt;Unit1&lt;/TD&gt;&lt;TD&gt;Drug of interest 2&lt;/TD&gt;&lt;TD&gt;Strength2&lt;/TD&gt;&lt;TD&gt;Unit2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;Amantadine&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;MG&lt;/TD&gt;&lt;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&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;Entacapone&lt;/TD&gt;&lt;TD&gt;200&lt;/TD&gt;&lt;TD&gt;MG&lt;/TD&gt;&lt;TD&gt;Amantadine&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;MG&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;Trihexyphenidyl&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;MG&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;Amantadine&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;MG&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;Trihexyphenidyl&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;MG&lt;/TD&gt;&lt;TD&gt;Entacapone&lt;/TD&gt;&lt;TD&gt;200&lt;/TD&gt;&lt;TD&gt;MG&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Sun, 29 Dec 2024 10:35:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-Out-Columns-Based-on-Conditions/m-p/954722#M372850</guid>
      <dc:creator>cheroij</dc:creator>
      <dc:date>2024-12-29T10:35:26Z</dc:date>
    </item>
    <item>
      <title>Re: Parse Out Columns Based on Conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-Out-Columns-Based-on-Conditions/m-p/954724#M372851</link>
      <description>&lt;P&gt;This parses the drug names (assuming a max length of 24 characters and that the separator is always a slash).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set have;
	array drug $ 24 drug1-drug3;
	do i=1 to countw(drug_name,'/');
		drug(i)=scan(drug_name,i,'/');
	end;
	drop i drug_name;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I leave it up to you to follow the above code and modify it to work on dosages.&lt;/P&gt;</description>
      <pubDate>Sun, 29 Dec 2024 11:48:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-Out-Columns-Based-on-Conditions/m-p/954724#M372851</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-12-29T11:48:13Z</dc:date>
    </item>
    <item>
      <title>Re: Parse Out Columns Based on Conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-Out-Columns-Based-on-Conditions/m-p/954726#M372852</link>
      <description>&lt;P&gt;Correction to the above code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set have;
	array drug $ 24 drug1-drug3;
	count=0;
	do i=1 to countw(drug_name,'/');
		this_drug=scan(drug_name,i,'/');
		if upcase(this_drug) in 
			('AMANTADINE', 'CARBIDOPA', 'ENTACAPONE', 'APOMORPHINE', 'TRIHEXYPHENIDYL', 'AMANTADINE', 'TRIHEXYPHENIDYL', 'LEVODOPA') then do;
		    count=count+1;
		    drug(count)=this_drug;
	    end;
	end;
	drop i drug_name count this_drug;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 29 Dec 2024 16:02:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-Out-Columns-Based-on-Conditions/m-p/954726#M372852</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-12-29T16:02:12Z</dc:date>
    </item>
    <item>
      <title>Re: Parse Out Columns Based on Conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-Out-Columns-Based-on-Conditions/m-p/954728#M372853</link>
      <description>&lt;P&gt;I would start by converting the dataset into one observation per drug.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First lets fix your example data step so it can run.&amp;nbsp; I will rename the variables to indicate the are LISTS and not normal values.&amp;nbsp; It is not clear to me what you are doing with the UNITS, so since it looks like a separate variable in your data lines I will make it a separate variable (even though it does not seem to have enough values).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data HAVE;
  input Patient_ID drugs :$60. strengths :$20. Units :$20. ;
datalines;
1 Carbidopa 25 MG
1 Carbidopa/Levodopa 25-100 MG
2 Levodopa/Entacapone 100-200 MG
2 Apomorphine 2 MG/ML
2 Ropinirole/Entacapone 2-200 MG
3 Levodopa/Entacapone/Ropinirole 100-200-2 MG
3 Pramipexole/Entacapone/Amantadine 1-200-100 MG
3 Pramipexole/Trihexyphenidyl 1-2 MG
4 Amantadine/Benztropine 100-1 MG
5 Trihexyphenidyl/Rasagiline/Entacapone 2-0.5-200 MG
;;;;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now just loop over the paired lists and parse out the DRUG_NAME and STRENGTH from the list.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  do index=1 to countw(drugs,'/');
    length drug_name $30 strength $10 unit $10 ;
    drug_name=scan(drugs,index,'/');
    strength=scan(strengths,index,'-');
    unit=scan(units,min(index,countw(units,'-')),'-');
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now your test for whether the drug is a drug of interest is simpler since DRUG_NAME now only has one value per observation.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1735491649215.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/103395iFD793B757D6A4384/image-size/large?v=v2&amp;amp;px=999" role="button" title="Tom_0-1735491649215.png" alt="Tom_0-1735491649215.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 29 Dec 2024 17:01:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-Out-Columns-Based-on-Conditions/m-p/954728#M372853</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-12-29T17:01:07Z</dc:date>
    </item>
    <item>
      <title>Re: Parse Out Columns Based on Conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-Out-Columns-Based-on-Conditions/m-p/954732#M372854</link>
      <description>&lt;P&gt;Don't saddle yourself with the burden of a wide dataset (Maxim 19).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dsd dlm=" " truncover;
length patient_id 8 drugs $40 strengths $12 unit $10;
input patient_id drugs strengths unit;
datalines;
1 Carbidopa 25 MG
1 Carbidopa/Levodopa 25-100 MG
2 Levodopa/Entacapone 100-200 MG
2 Apomorphine 2 MG/ML
2 Ropinirole/Entacapone 2-200 MG
3 Levodopa/Entacapone/Ropinirole 100-200-2 MG
3 Pramipexole/Entacapone/Amantadine 1-200-100 MG
3 Pramipexole/Trihexyphenidyl 1-2 MG
4 Amantadine/Benztropine 100-1 MG
5 Trihexyphenidyl/Rasagiline/Entacapone 2-0.5-200 MG
;

data interest;
length drug $20;
input drug;
drug = upcase(drug);
datalines;
Amantadine
Carbidopa
Entacapone
Apomorphine
Trihexyphenidyl
Amantadine
Trihexyphenidyl
levodopa
;

data want;
retain patient_id n n1 drug strength unit; * just for variable order;
set have;
length drug $20 strength 8 n 8 n1 8;
by patient_id;
if _n_ = 1
then do;
  declare hash int (dataset:"interest");
  int.definekey("drug");
  int.definedone();
end;
if first.patient_id
then n = 1;
else n + 1;
n1 = 0;
do i = 1 to countw(drugs,"/");
  drug = scan(drugs,i,"/");
  strength = input(scan(strengths,i,"-"),32.);
  if int.check(key:upcase(drug)) = 0
  then do;
    n1 + 1;
    output;
  end;
end;
keep patient_id drug strength unit n n1;
run;

proc report data=want;
column patient_id n n1,(drug unit strength);
define patient_id / group;
define n / group noprint;
define n1 / "" across;
define drug / display;
define unit / display;
define strength / analysis;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I created additional variables to get a report like you showed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 29 Dec 2024 19:39:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-Out-Columns-Based-on-Conditions/m-p/954732#M372854</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-12-29T19:39:47Z</dc:date>
    </item>
    <item>
      <title>Re: Parse Out Columns Based on Conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-Out-Columns-Based-on-Conditions/m-p/954742#M372859</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WORK.HAVE;
infile datalines  truncover;
input Patient_ID:32. Drug_Name:$37. Strength $12.;
label Patient_ID="Patient ID" Drug_Name="Drug_Name" Strength="Strength";
datalines;
1 Carbidopa 25 MG
1 Carbidopa/Levodopa 25-100 MG
2 Levodopa/Entacapone 100-200 MG
2 Apomorphine 2 MG/ML
2 Ropinirole/Entacapone 2-200 MG
3 Levodopa/Entacapone/Ropinirole 100-200-2 MG
3 Pramipexole/Entacapone/Amantadine 1-200-100 MG
3 Pramipexole/Trihexyphenidyl 1-2 MG
4 Amantadine/Benztropine 100-1 MG
5 Trihexyphenidyl/Rasagiline/Entacapone 2-0.5-200 MG
;
data temp;
 set have;
 n+1;
 do i=1 to countw(Drug_Name,'/');
  Drug_of_Interest_=scan(Drug_Name,i,'/');
  Strength_=scan(Strength,i,'-','s');
  Unit_=scan(Strength,-1,,'s');
  if prxmatch('/Amantadine|Carbidopa|Entacapone|Apomorphine|Trihexyphenidyl|levodopa/i',Drug_of_Interest_) then output;
 end;
 keep n  Patient_ID Drug_of_Interest_ Strength_  Unit_;
 run;
 data temp2;
  set temp;
  by n;
  if first.n then id=0;
  id+1;
run;
 proc transpose data=temp2 out=temp3;
 by n id Patient_ID;
 var Drug_of_Interest_ Strength_  Unit_;
 run;
 proc transpose data=temp3 out=want(drop=_name_);
 by n Patient_ID;
 var col1;
 id _name_ id;
 run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1735524836178.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/103401iCCE3B8A83D70E239/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1735524836178.png" alt="Ksharp_0-1735524836178.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Dec 2024 02:14:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-Out-Columns-Based-on-Conditions/m-p/954742#M372859</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-12-30T02:14:07Z</dc:date>
    </item>
    <item>
      <title>Re: Parse Out Columns Based on Conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-Out-Columns-Based-on-Conditions/m-p/954780#M372872</link>
      <description>&lt;P&gt;Thank you for your response and your time. This code did not parse out the strength variaable.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Dec 2024 15:56:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-Out-Columns-Based-on-Conditions/m-p/954780#M372872</guid>
      <dc:creator>cheroij</dc:creator>
      <dc:date>2024-12-30T15:56:51Z</dc:date>
    </item>
    <item>
      <title>Re: Parse Out Columns Based on Conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-Out-Columns-Based-on-Conditions/m-p/954781#M372873</link>
      <description>&lt;P&gt;Thank you for your response. I had to make some teaks to the code. I apologize for my sample data not being clear.&amp;nbsp; The strength variable included the unit as well (ie unit is not a separate column in my data)&lt;/P&gt;</description>
      <pubDate>Mon, 30 Dec 2024 15:59:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-Out-Columns-Based-on-Conditions/m-p/954781#M372873</guid>
      <dc:creator>cheroij</dc:creator>
      <dc:date>2024-12-30T15:59:10Z</dc:date>
    </item>
    <item>
      <title>Re: Parse Out Columns Based on Conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-Out-Columns-Based-on-Conditions/m-p/954782#M372874</link>
      <description>&lt;P&gt;Thank you&lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Dec 2024 15:59:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-Out-Columns-Based-on-Conditions/m-p/954782#M372874</guid>
      <dc:creator>cheroij</dc:creator>
      <dc:date>2024-12-30T15:59:54Z</dc:date>
    </item>
    <item>
      <title>Re: Parse Out Columns Based on Conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-Out-Columns-Based-on-Conditions/m-p/954783#M372875</link>
      <description>&lt;P&gt;Thank you for your response. Your code worked with minor tweaks. Sorry about the confusion in data sample provided.The nint column is not a separate column in my dataset.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Dec 2024 16:04:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-Out-Columns-Based-on-Conditions/m-p/954783#M372875</guid>
      <dc:creator>cheroij</dc:creator>
      <dc:date>2024-12-30T16:04:23Z</dc:date>
    </item>
    <item>
      <title>Re: Parse Out Columns Based on Conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parse-Out-Columns-Based-on-Conditions/m-p/954784#M372876</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/424140"&gt;@cheroij&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;... The strength variable included the unit as well (ie unit is not a separate column in my data)&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You might need to revisit that decision.&amp;nbsp; The units for all drugs taken by a patient are not always going to be the same.&amp;nbsp; And even if your drug lists just represent single pill combination drugs then not all of those will have the strengths listed using the same units.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Dec 2024 16:50:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parse-Out-Columns-Based-on-Conditions/m-p/954784#M372876</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-12-30T16:50:48Z</dc:date>
    </item>
  </channel>
</rss>

