<?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 Spliting a String into 3 observations using an Identifier in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Spliting-a-String-into-3-observations-using-an-Identifier/m-p/403659#M12279</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi SAS Community, I need you help in the following problem.&lt;/P&gt;&lt;P&gt;I have a dataset that looks like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;NDC&lt;/TD&gt;&lt;TD&gt;PHARM_CLASSES&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;21434&lt;/TD&gt;&lt;TD&gt;GLP-1 Receptor Agonist [EPC],Glucagon-Like Peptide 1 [Chemical/Ingredient],Glucagon-like Peptide-1 (GLP-1) Agonists [MoA]&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;21445&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;21975&lt;/TD&gt;&lt;TD&gt;Androgen [EPC],Androgen Receptor Agonists [MoA],Androstanes [Chemical/Ingredient]&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;21977&lt;/TD&gt;&lt;TD&gt;Androgen [EPC],Androgen Receptor Agonists [MoA],Androstanes [Chemical/Ingredient]&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;23004&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;23227&lt;/TD&gt;&lt;TD&gt;Norepinephrine Reuptake Inhibitor [EPC],Norepinephrine Uptake Inhibitors [MoA]&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and I am hoping to get an output like this&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;NDC&lt;/TD&gt;&lt;TD&gt;EPC&lt;/TD&gt;&lt;TD&gt;MoA&lt;/TD&gt;&lt;TD&gt;Chemical Ingredient&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;21434&lt;/TD&gt;&lt;TD&gt;GLP-1 Receptor Agonist&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Glucagon-like Peptide-1 (GLP-1) Agonists&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Glucagon-Like Peptide 1&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;21445&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;21975&lt;/TD&gt;&lt;TD&gt;Androgen&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Androgen Receptor Agonists&lt;/TD&gt;&lt;TD&gt;Androstanes&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;21977&lt;/TD&gt;&lt;TD&gt;Androgen&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Androgen Receptor Agonists&lt;/TD&gt;&lt;TD&gt;Androstanes&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;23004&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;23227&lt;/TD&gt;&lt;TD&gt;Norepinephrine Reuptake Inhibitor&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Norepinephrine Uptake Inhibitors&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;I have got help for the same problem previously but, I get a WARNING: 2761 observations omitted due to missing values in the ID variables due to PROC TRANSPOSE. I don't want to loose any observation.&amp;nbsp; Can anyone help me with this problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; 
data middle;
  set NDCdata(Keep= PHARM_CLASSES  NDC);
  length term $150 tag $20 ;
  do i=1 by 1 until (term=' ');
    term=strip(scan(PHARM_CLASSES,i,','));
    tag=scan(term,2,'[]');
    if term ne ' ' then output;
  end;
run;

proc sort data=middle ;
  by NDC tag ;
run;

data middle2 ;
  set middle ;
  by NDC tag ;
  rep+1;
  if first.tag then rep=1;
run;

proc transpose data=middle2 out=want(drop=_name_) ;
  by  NDC;
  id tag rep ;
  var term ;
run;

data cc;
set want (Keep = NDC Chemical_Ingredient1 EPC1 MoA1);
run;

proc sort data = b out = bsort Tagsort nodupkey;
by NDC;
run;

proc sort data = cc out = ccsort Tagsort nodupkey;
by NDC;
run;


 data dd ; 
   merge bsort ccsort ; 
   by NDC ; 
   where NDC ^= '.' ; 
   drop productID;
 run&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 12 Oct 2017 19:18:22 GMT</pubDate>
    <dc:creator>shasank</dc:creator>
    <dc:date>2017-10-12T19:18:22Z</dc:date>
    <item>
      <title>Spliting a String into 3 observations using an Identifier</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Spliting-a-String-into-3-observations-using-an-Identifier/m-p/403659#M12279</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi SAS Community, I need you help in the following problem.&lt;/P&gt;&lt;P&gt;I have a dataset that looks like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;NDC&lt;/TD&gt;&lt;TD&gt;PHARM_CLASSES&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;21434&lt;/TD&gt;&lt;TD&gt;GLP-1 Receptor Agonist [EPC],Glucagon-Like Peptide 1 [Chemical/Ingredient],Glucagon-like Peptide-1 (GLP-1) Agonists [MoA]&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;21445&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;21975&lt;/TD&gt;&lt;TD&gt;Androgen [EPC],Androgen Receptor Agonists [MoA],Androstanes [Chemical/Ingredient]&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;21977&lt;/TD&gt;&lt;TD&gt;Androgen [EPC],Androgen Receptor Agonists [MoA],Androstanes [Chemical/Ingredient]&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;23004&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;23227&lt;/TD&gt;&lt;TD&gt;Norepinephrine Reuptake Inhibitor [EPC],Norepinephrine Uptake Inhibitors [MoA]&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and I am hoping to get an output like this&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;NDC&lt;/TD&gt;&lt;TD&gt;EPC&lt;/TD&gt;&lt;TD&gt;MoA&lt;/TD&gt;&lt;TD&gt;Chemical Ingredient&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;21434&lt;/TD&gt;&lt;TD&gt;GLP-1 Receptor Agonist&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Glucagon-like Peptide-1 (GLP-1) Agonists&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Glucagon-Like Peptide 1&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;21445&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;21975&lt;/TD&gt;&lt;TD&gt;Androgen&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Androgen Receptor Agonists&lt;/TD&gt;&lt;TD&gt;Androstanes&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;21977&lt;/TD&gt;&lt;TD&gt;Androgen&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Androgen Receptor Agonists&lt;/TD&gt;&lt;TD&gt;Androstanes&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;23004&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;23227&lt;/TD&gt;&lt;TD&gt;Norepinephrine Reuptake Inhibitor&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;Norepinephrine Uptake Inhibitors&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;I have got help for the same problem previously but, I get a WARNING: 2761 observations omitted due to missing values in the ID variables due to PROC TRANSPOSE. I don't want to loose any observation.&amp;nbsp; Can anyone help me with this problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; 
data middle;
  set NDCdata(Keep= PHARM_CLASSES  NDC);
  length term $150 tag $20 ;
  do i=1 by 1 until (term=' ');
    term=strip(scan(PHARM_CLASSES,i,','));
    tag=scan(term,2,'[]');
    if term ne ' ' then output;
  end;
run;

proc sort data=middle ;
  by NDC tag ;
run;

data middle2 ;
  set middle ;
  by NDC tag ;
  rep+1;
  if first.tag then rep=1;
run;

proc transpose data=middle2 out=want(drop=_name_) ;
  by  NDC;
  id tag rep ;
  var term ;
run;

data cc;
set want (Keep = NDC Chemical_Ingredient1 EPC1 MoA1);
run;

proc sort data = b out = bsort Tagsort nodupkey;
by NDC;
run;

proc sort data = cc out = ccsort Tagsort nodupkey;
by NDC;
run;


 data dd ; 
   merge bsort ccsort ; 
   by NDC ; 
   where NDC ^= '.' ; 
   drop productID;
 run&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Oct 2017 19:18:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Spliting-a-String-into-3-observations-using-an-Identifier/m-p/403659#M12279</guid>
      <dc:creator>shasank</dc:creator>
      <dc:date>2017-10-12T19:18:22Z</dc:date>
    </item>
    <item>
      <title>Re: Spliting a String into 3 observations using an Identifier</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Spliting-a-String-into-3-observations-using-an-Identifier/m-p/403669#M12280</link>
      <description>&lt;P&gt;It is possible that the original code&amp;nbsp; you are working with is overkill and could be simplified considerably.&amp;nbsp; The right route depends on how well you know what is in your data.&amp;nbsp; For a single observation, is it possible that there is more than one MoA compound listed?&amp;nbsp; (That question applies to EPC and Chemical/Ingredient as well.)&amp;nbsp; If not, extreme simplifications are in order.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Oct 2017 19:49:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Spliting-a-String-into-3-observations-using-an-Identifier/m-p/403669#M12280</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-10-12T19:49:50Z</dc:date>
    </item>
    <item>
      <title>Re: Spliting a String into 3 observations using an Identifier</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Spliting-a-String-into-3-observations-using-an-Identifier/m-p/403676#M12281</link>
      <description>Hi Astounding,&lt;BR /&gt;Yes, There are more than 1 occurrences, but I need only the 1st occurrence i:e I Need only the 1st MoA even if 2 MoA or greater are present.&lt;BR /&gt;Will this simplify the problem??</description>
      <pubDate>Thu, 12 Oct 2017 20:01:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Spliting-a-String-into-3-observations-using-an-Identifier/m-p/403676#M12281</guid>
      <dc:creator>shasank</dc:creator>
      <dc:date>2017-10-12T20:01:03Z</dc:date>
    </item>
    <item>
      <title>Re: Spliting a String into 3 observations using an Identifier</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Spliting-a-String-into-3-observations-using-an-Identifier/m-p/403687#M12282</link>
      <description>&lt;P&gt;Sure, that's enough to simplify.&amp;nbsp; This is untested, so might need minor tweaking:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;length EPC MoA Chemical_Ingredient term $ 150 tag $ 20;&lt;/P&gt;
&lt;P&gt;do j=1 by 1 until (term=' ');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; term = scan(PHARM_CLASSES, j, ',');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if term &amp;gt; ' ' then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tag = scan(term, 2, '][');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if upcase(tag) = 'MOA' and MoA=' ' then MoA = scan(term, 1, '][');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if upcase(tag) = 'EPC' and EPC=' ' then EPC = scan(term, 1, '][');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if upcase(tag) = 'CHEMICAL/INGREDIENT' and Chemical_Ingredient = ' ' then Chemical_Ingredient = scan(term, 1, '][');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;drop j&amp;nbsp;term tag PHARM_CLASSES;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might want to keep PHARM_CLASSSES at first, until you are confident that the results are correct.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Oct 2017 20:15:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Spliting-a-String-into-3-observations-using-an-Identifier/m-p/403687#M12282</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-10-12T20:15:56Z</dc:date>
    </item>
    <item>
      <title>Re: Spliting a String into 3 observations using an Identifier</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Spliting-a-String-into-3-observations-using-an-Identifier/m-p/403688#M12283</link>
      <description>Worked like a charm.&lt;BR /&gt;&lt;BR /&gt;Thanks a lot.</description>
      <pubDate>Thu, 12 Oct 2017 20:28:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Spliting-a-String-into-3-observations-using-an-Identifier/m-p/403688#M12283</guid>
      <dc:creator>shasank</dc:creator>
      <dc:date>2017-10-12T20:28:06Z</dc:date>
    </item>
    <item>
      <title>Re: Spliting a String into 3 observations using an Identifier</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Spliting-a-String-into-3-observations-using-an-Identifier/m-p/403703#M12284</link>
      <description>&lt;P&gt;This is a late response, but is a little easier to generalize to several/dozens of variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input NDC PHARM_CLASSES :$&amp;amp;200. ;
datalines;
21434 GLP-1 Receptor Agonist [EPC],Glucagon-Like Peptide 1 [Chemical/Ingredient],Glucagon-like Peptide-1 (GLP-1) Agonists [MoA] 
21445 . 
21975 Androgen [EPC],Androgen Receptor Agonists [MoA],Androstanes [Chemical/Ingredient] 
21977 Androgen [EPC],Androgen Receptor Agonists [MoA],Androstanes [Chemical/Ingredient] 
23004 . 
23227 Norepinephrine Reuptake Inhibitor [EPC],Norepinephrine Uptake Inhibitors [MoA] 
run;
data want (drop=_:);
  set have;
  array vars{3} $60 epc chemical_ingredient moa;

  length _tag_list $40 ;
  retain _tag_list '[EPC] [Chemical/Ingredient] [MoA]';
 
  do _P=1  by 1 while(scan(pharm_classes,_P,',')^='');       
     _value_tag_pair=scan(pharm_classes,_P,',');             
	 _v=findw(_tag_list,trim(scan(_value_tag_pair,-1,' ')),' ','e');    
	 if _v^=0 then vars{_v}=scan(_value_tag_pair,1,'[');               
  end;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This works by searching the tag-in-hand against the tag_list, yielding the position of the current tag in the list.&amp;nbsp; This position (_V) is used to assign a value to the appropriate element in character-array VARS.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Oct 2017 21:11:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Spliting-a-String-into-3-observations-using-an-Identifier/m-p/403703#M12284</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-10-12T21:11:09Z</dc:date>
    </item>
    <item>
      <title>Re: Spliting a String into 3 observations using an Identifier</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Spliting-a-String-into-3-observations-using-an-Identifier/m-p/403722#M12285</link>
      <description>Thanks alot. This helps.&lt;BR /&gt;</description>
      <pubDate>Thu, 12 Oct 2017 22:02:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Spliting-a-String-into-3-observations-using-an-Identifier/m-p/403722#M12285</guid>
      <dc:creator>shasank</dc:creator>
      <dc:date>2017-10-12T22:02:49Z</dc:date>
    </item>
  </channel>
</rss>

