<?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: Computing a new variable based on character range in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Computing-a-new-variable-based-on-character-range/m-p/613284#M18386</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input PatientID   CCIcode :$15.;
cards;
1                1GR89QB    1GR89O
2                1AB76EA     1AB76E
3                1CG57KZ    1CG57O
4                1CG57KS    1CG57E
;

data want;
set have;
k=substr(CCIcode,6,2);
if  'AA'&amp;lt;=k&amp;lt;='KS' then newcode=cats(substr(CCIcode,1,5),'E');
else if 'KZ'&amp;lt;=k&amp;lt;='XY' then newcode=cats(substr(CCIcode,1,5),'O');
drop k;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 20 Dec 2019 17:43:47 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2019-12-20T17:43:47Z</dc:date>
    <item>
      <title>Computing a new variable based on character range</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Computing-a-new-variable-based-on-character-range/m-p/613279#M18384</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to compute a new variable based on the character values in the 6th and 7th position of an existing column. For example, I'd like to try to compute the column Newcode from CCIcode:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PatientID&amp;nbsp; &amp;nbsp; CCIcode&amp;nbsp; &amp;nbsp; &amp;nbsp;Newcode&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1GR89QB&amp;nbsp; &amp;nbsp; 1GR89O&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1AB76EA&amp;nbsp; &amp;nbsp; &amp;nbsp;1AB76E&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1CG57KZ&amp;nbsp; &amp;nbsp; 1CG57O&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1CG57KS&amp;nbsp; &amp;nbsp; 1CG57E&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Essentially, if position 6 &amp;amp; 7 of the variable CCIcode are AA-KS, then I'd like position 6 of Newcode to be "E". If position 6 &amp;amp; 7 of the variable CCIcode are KZ-XY (there is nothing inbetween KS to KZ) then I'd like position 6 of Newcode to be "O".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried a few variations of substr code, but I don't know how to specify the character ranges without having to type the letters individually. Any help here would be much much appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 20 Dec 2019 17:31:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Computing-a-new-variable-based-on-character-range/m-p/613279#M18384</guid>
      <dc:creator>bretthouston</dc:creator>
      <dc:date>2019-12-20T17:31:30Z</dc:date>
    </item>
    <item>
      <title>Re: Computing a new variable based on character range</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Computing-a-new-variable-based-on-character-range/m-p/613280#M18385</link>
      <description>&lt;P&gt;How is the range&amp;nbsp;&lt;SPAN&gt;AA-KS defined?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Dec 2019 17:36:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Computing-a-new-variable-based-on-character-range/m-p/613280#M18385</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-12-20T17:36:16Z</dc:date>
    </item>
    <item>
      <title>Re: Computing a new variable based on character range</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Computing-a-new-variable-based-on-character-range/m-p/613284#M18386</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input PatientID   CCIcode :$15.;
cards;
1                1GR89QB    1GR89O
2                1AB76EA     1AB76E
3                1CG57KZ    1CG57O
4                1CG57KS    1CG57E
;

data want;
set have;
k=substr(CCIcode,6,2);
if  'AA'&amp;lt;=k&amp;lt;='KS' then newcode=cats(substr(CCIcode,1,5),'E');
else if 'KZ'&amp;lt;=k&amp;lt;='XY' then newcode=cats(substr(CCIcode,1,5),'O');
drop k;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 Dec 2019 17:43:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Computing-a-new-variable-based-on-character-range/m-p/613284#M18386</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-12-20T17:43:47Z</dc:date>
    </item>
    <item>
      <title>Re: Computing a new variable based on character range</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Computing-a-new-variable-based-on-character-range/m-p/613286#M18387</link>
      <description>&lt;P&gt;Thank-you so much - this is exactly what I was looking for! Works perfectly!&lt;/P&gt;</description>
      <pubDate>Fri, 20 Dec 2019 17:47:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Computing-a-new-variable-based-on-character-range/m-p/613286#M18387</guid>
      <dc:creator>bretthouston</dc:creator>
      <dc:date>2019-12-20T17:47:03Z</dc:date>
    </item>
    <item>
      <title>Re: Computing a new variable based on character range</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Computing-a-new-variable-based-on-character-range/m-p/613288#M18388</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/268580"&gt;@bretthouston&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can also use a PRX function to look for specific patterns:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set have;
	if prxmatch('/^.{5}[A-J][A-Z]$|^.{5}K[A-S]$/',strip(CCIcode))
		then Newcode = prxchange('s/[A-J][A-Z]$|K[A-S]$/E/',1,strip(CCIcode));
	else if prxmatch('/^.{5}KZ$|^.{5}[L-W][A-Z]$|^.{5}X[A-Y]$/',strip(CCIcode))
		then Newcode = prxchange('s/KZ$|[L-W][A-Z]$|X[A-Y]$/O/',1,strip(CCIcode));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 Dec 2019 17:57:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Computing-a-new-variable-based-on-character-range/m-p/613288#M18388</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2019-12-20T17:57:49Z</dc:date>
    </item>
  </channel>
</rss>

