<?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 expected values from a character string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-expected-values-from-a-character-string/m-p/282568#M57451</link>
    <description>&lt;P&gt;Split first using the semi-colon as the delimiter.&lt;/P&gt;&lt;P&gt;Then check if the split element&amp;nbsp;starts with 'ATC' and if it does take the 2nd and 3rd element.&lt;/P&gt;&lt;PRE&gt;data have;

CLIST="ATC|N|NERVOUS SYSTEM; ATC|N06|PSYCHOANALEPTICS; ATC|N06B|PSYCHOSTIMULANTS, AGENTS USED FOR ADHD AND NOOTROPICS; ATC|N06BA|CENTRALLY ACTING SYMPATHOMIMETICS; PRODUCT|062107 01 001|ARMODAFINIL; PRODUCTSYNONYM|062107 01 002|NUVIGIL;";
output; 
clist="ATC|R|RESPIRATORY SYSTEM; ATC|R05|COUGH AND COLD PREPARATIONS; ATC|R05X|OTHER COLD PREPARATIONS; PRODUCT|000558 01 001|VICK VAPOUR-RUB; PRODUCTSYNONYM|000558 01 002|VICKS VAPORUB /00055801/;";
output; 
run;

data want (drop=clist clistpart i);
set have;
array CMATC{4} $50  CMATC1-CMATC4;
array CMATCXC{4} $8 CMATC1C CMATC2C CMATC3C CMATC4C ;
do i=1 to dim(CMATC);
clistpart=strip(scan(clist,i,';'));
if clistpart=:"ATC"  then do;
CMATC[i] = scan(clistpart,3,'|;/');
CMATCXC[i] = scan(clistpart,2,'|;/');
end;
end;
run;&lt;/PRE&gt;</description>
    <pubDate>Wed, 06 Jul 2016 22:40:56 GMT</pubDate>
    <dc:creator>JohnHoughton</dc:creator>
    <dc:date>2016-07-06T22:40:56Z</dc:date>
    <item>
      <title>How to expected values from a character string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-expected-values-from-a-character-string/m-p/282553#M57446</link>
      <description>&lt;P&gt;Dear,&lt;/P&gt;&lt;P&gt;I have a variable(clist) has values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;CLIST&lt;/P&gt;&lt;P&gt;1.&amp;nbsp;&lt;FONT color="#FF6600"&gt;ATC&lt;/FONT&gt;|N|NERVOUS SYSTEM; &lt;FONT color="#FF6600"&gt;ATC&lt;/FONT&gt;|N06|PSYCHOANALEPTICS; &lt;FONT color="#FF6600"&gt;ATC&lt;/FONT&gt;|N06B|PSYCHOSTIMULANTS, AGENTS USED FOR ADHD AND NOOTROPICS; &lt;FONT color="#FF6600"&gt;ATC&lt;/FONT&gt;|N06BA|CENTRALLY ACTING SYMPATHOMIMETICS; PRODUCT|062107 01 001|ARMODAFINIL; PRODUCTSYNONYM|062107 01 002|NUVIGIL;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2.&lt;FONT color="#FF6600"&gt;ATC&lt;/FONT&gt;|R|RESPIRATORY SYSTEM; &lt;FONT color="#FF6600"&gt;ATC&lt;/FONT&gt;|R05|COUGH AND COLD PREPARATIONS; &lt;FONT color="#FF6600"&gt;ATC&lt;/FONT&gt;|R05X|OTHER COLD PREPARATIONS; PRODUCT|000558 01 001|VICK VAPOUR-RUB; PRODUCTSYNONYM|000558 01 002|VICKS VAPORUB /00055801/;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to extract the ATC values(ATC values start with ATC) from it into 4 variables;&lt;/P&gt;&lt;P&gt;By using the following code I am getting the expecting output for first observation. But for second observation, eventhough 4th ATC value is missing but values are populated for CMATC4 and CMATC4C. The values for&amp;nbsp;&lt;SPAN&gt;CMATC4 and CMATC4C should be blank as there is no 4th ATC. Please help&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code used:&lt;BR /&gt;CMATC1 = scan(clist,3,'|;/');&lt;BR /&gt;CMATC1C = scan(clist,2,'|;/');&lt;BR /&gt;CMATC2 = scan(clist,6,'|;/');&lt;BR /&gt;CMATC2C = scan(clist,5,'|;/');&lt;BR /&gt;CMATC3 = scan(clist,9,'|;/');&lt;BR /&gt;CMATC3C = scan(clist,8,'|;/');&lt;BR /&gt;CMATC4 = scan(clist,12,'|;/');&lt;BR /&gt;CMATC4C = scan(clist,11,'|;/');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;expecting for the output:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;for first observation:&lt;/P&gt;&lt;P&gt;CMATC1C= 'NERVOUS SYSTEM';&lt;BR /&gt;CMATC1='N';&lt;BR /&gt;&lt;BR /&gt;CMATC2C='PSYCHOANALEPTICS';&lt;BR /&gt;CMATC2='N06';&lt;BR /&gt;&lt;BR /&gt;CMATC3C='PSYCHOSTIMULANTS, AGENTS USED FOR ADHD AND NOOTROPICS';&lt;BR /&gt;CMATC3='N06B';&lt;BR /&gt;&lt;BR /&gt;CMATC4C='CENTRALLY ACTING SYMPATHOMIMETICS';&lt;BR /&gt;CMATC4='N06BA';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for second observation:&lt;/P&gt;&lt;P&gt;CMATC1C= 'RESPIRATORY SYSTEM';&lt;BR /&gt;CMATC1='R';&lt;BR /&gt;&lt;BR /&gt;CMATC2C='COUGH AND COLD PREPARATIONS';&lt;BR /&gt;CMATC2='R05';&lt;BR /&gt;&lt;BR /&gt;CMATC3C='OTHER COLD PREPARATIONS';&lt;BR /&gt;CMATC3='R05x';&lt;BR /&gt;&lt;BR /&gt;CMATC4C='';&lt;BR /&gt;CMATC4='';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jul 2016 21:19:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-expected-values-from-a-character-string/m-p/282553#M57446</guid>
      <dc:creator>knveraraju91</dc:creator>
      <dc:date>2016-07-06T21:19:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to expected values from a character string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-expected-values-from-a-character-string/m-p/282568#M57451</link>
      <description>&lt;P&gt;Split first using the semi-colon as the delimiter.&lt;/P&gt;&lt;P&gt;Then check if the split element&amp;nbsp;starts with 'ATC' and if it does take the 2nd and 3rd element.&lt;/P&gt;&lt;PRE&gt;data have;

CLIST="ATC|N|NERVOUS SYSTEM; ATC|N06|PSYCHOANALEPTICS; ATC|N06B|PSYCHOSTIMULANTS, AGENTS USED FOR ADHD AND NOOTROPICS; ATC|N06BA|CENTRALLY ACTING SYMPATHOMIMETICS; PRODUCT|062107 01 001|ARMODAFINIL; PRODUCTSYNONYM|062107 01 002|NUVIGIL;";
output; 
clist="ATC|R|RESPIRATORY SYSTEM; ATC|R05|COUGH AND COLD PREPARATIONS; ATC|R05X|OTHER COLD PREPARATIONS; PRODUCT|000558 01 001|VICK VAPOUR-RUB; PRODUCTSYNONYM|000558 01 002|VICKS VAPORUB /00055801/;";
output; 
run;

data want (drop=clist clistpart i);
set have;
array CMATC{4} $50  CMATC1-CMATC4;
array CMATCXC{4} $8 CMATC1C CMATC2C CMATC3C CMATC4C ;
do i=1 to dim(CMATC);
clistpart=strip(scan(clist,i,';'));
if clistpart=:"ATC"  then do;
CMATC[i] = scan(clistpart,3,'|;/');
CMATCXC[i] = scan(clistpart,2,'|;/');
end;
end;
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Jul 2016 22:40:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-expected-values-from-a-character-string/m-p/282568#M57451</guid>
      <dc:creator>JohnHoughton</dc:creator>
      <dc:date>2016-07-06T22:40:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to expected values from a character string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-expected-values-from-a-character-string/m-p/282570#M57452</link>
      <description>&lt;P&gt;You have now moved into the realm of PARSING a line of data. If I recall from a previous thread, YOU created the CLIST. It is likely time to go back and consider what you are actually doing with CLIST and if you should have placed it all one line.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This would be much easier to manage (probably for many purposes) if the data looked more like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Keyvalue1|ATC|N|NERVOUS SYSTEM; 
Keyvalue1|ATC|N06|PSYCHOANALEPTICS; 
Keyvalue1|ATC|N06B|PSYCHOSTIMULANTS, AGENTS USED FOR ADHD AND NOOTROPICS; 
Keyvalue1|ATC|N06BA|CENTRALLY ACTING SYMPATHOMIMETICS; 
Keyvalue1|PRODUCT|062107 01 001|ARMODAFINIL; 
Keyvalue1|PRODUCTSYNONYM|062107 01 002|NUVIGIL;
Keyvalue2|ATC|R|RESPIRATORY SYSTEM; 
Keyvalue2|ATC|R05|COUGH AND COLD PREPARATIONS; 
Keyvalue2|ATC|R05X|OTHER COLD PREPARATIONS; 
Keyvalue2|PRODUCT|000558 01 001|VICK VAPOUR-RUB; 
Keyvalue2|PRODUCTSYNONYM|000558 01 002|VICKS VAPORUB /00055801/;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And you had variables to indicate the Keyvalue, role (ATC, Product, ProductSynonym) and similar (or possibly have the Product and Productsynonym on the first ATC line only and RETAIN the information).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you have anything that might have only 2 ATC? How about 5? Having the data in that "wide" format means extra parsing in may places for other coding but if you have one observation then the code is likely to much&amp;nbsp;simpler in the long run.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jul 2016 22:47:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-expected-values-from-a-character-string/m-p/282570#M57452</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-07-06T22:47:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to expected values from a character string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-expected-values-from-a-character-string/m-p/282583#M57456</link>
      <description>&lt;P&gt;You didn't post the output you want yet .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
CLIST="ATC|N|NERVOUS SYSTEM; ATC|N06|PSYCHOANALEPTICS; ATC|N06B|PSYCHOSTIMULANTS, AGENTS USED FOR ADHD AND NOOTROPICS; ATC|N06BA|CENTRALLY ACTING SYMPATHOMIMETICS; PRODUCT|062107 01 001|ARMODAFINIL; PRODUCTSYNONYM|062107 01 002|NUVIGIL;";
output; 
clist="ATC|R|RESPIRATORY SYSTEM; ATC|R05|COUGH AND COLD PREPARATIONS; ATC|R05X|OTHER COLD PREPARATIONS; PRODUCT|000558 01 001|VICK VAPOUR-RUB; PRODUCTSYNONYM|000558 01 002|VICKS VAPORUB /00055801/;";
output; 
run;
data temp;
 set have;
 n+1;
 pid=prxparse('/ATC[\|;\/][^\|;\/]+[\|;\/][^\|;\/]+/io');
 start=1;
 stop=length(clist);
 call prxnext(pid,start,stop,clist,p,l);
 do while(p&amp;gt;0);
  temp=substr(clist,p,l);
  CMATC = scan(temp,2,'|');
  CMATCC = scan(temp,3,'|');
  output;
  call prxnext(pid,start,stop,clist,p,l);
 end;
keep n clist CMATC CMATCC ;
run;
proc sql noprint;
select max(n) into : n 
 from (select count(*) as n from temp group by n);
quit;
proc summary data=temp;
by n clist;
output out=want idgroup(out[&amp;amp;n] (CMATC CMATCC)=);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Jul 2016 01:07:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-expected-values-from-a-character-string/m-p/282583#M57456</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-07-07T01:07:04Z</dc:date>
    </item>
  </channel>
</rss>

