<?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: Categorize a variable by ranges of values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Categorize-a-variable-by-ranges-of-values/m-p/468874#M119815</link>
    <description>&lt;P&gt;That’s not going to work. Where do you groupings live? In your head, or in an Excel file? Can it be made into a data set? I strongly second the PROC FORMAT option, ideally driven by a data set from Excel or creating a table using cards/datalines.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have issues post your code and we’ll help you modify it.&lt;/P&gt;</description>
    <pubDate>Fri, 08 Jun 2018 21:37:29 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-06-08T21:37:29Z</dc:date>
    <item>
      <title>Categorize a variable by ranges of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Categorize-a-variable-by-ranges-of-values/m-p/468871#M119813</link>
      <description>&lt;P&gt;I have ICD9 procedure codes to categorize by generic ranges. Is there more efficient way to do this work not necessarily spelling them out by each value in the range, like i shown for icd9_EYE below? It can be so tedious since I have to deal with cpt and icd-10 codes where I need to deal with ranges in similar fashion too. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if proc_cd in ('08', '09', '10','11','12','13','14','15','16') then flag='icd9_EYE';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if proc_cd in ('00') then   flag='icd9_NOS';
if proc_cd in ('01-05) then flag='icd9_NERVOUS' ;
if proc_cd in ('06-07) then flag='icd9_ENDOCRINE';
if proc_cd in ('08-16) then flag='icd9_EYE';
if proc_cd in ('17) then flag='icd9_MISC';
if proc_cd in ('18-20) then flag='icd9_EAR'
if proc_cd in ('21-29) then flag='icd9_NOSE_MOUTH_PHARYNX';
if proc_cd in ('30-34) then flag='icd9_RESPIRATORY';
if proc_cd in ('35-39) then flag='icd9_CVD';
if proc_cd in ('40-41) then flag='icd9_HEMIC_LYMPH';
if proc_cd in ('42-54) then flag='icd9_DIGEST';
if proc_cd in ('55-59) then flag='icd9_URINARY';
if proc_cd in ('60-64) then flag='icd9_MALE_GEN';
if proc_cd in ('65-71) then flag='icd9_FEMALE_GEN';
if proc_cd in ('72-75) then flag='icd9_OBSTET';
if proc_cd in ('76-84) then flag='icd9_MUS_SKEL';
if proc_cd in ('85-86) then flag='icd9_INTEGUMENTARY';
if proc_cd in ('87-99) then flag='icd9_MISC';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jun 2018 21:30:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Categorize-a-variable-by-ranges-of-values/m-p/468871#M119813</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2018-06-08T21:30:37Z</dc:date>
    </item>
    <item>
      <title>Re: Categorize a variable by ranges of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Categorize-a-variable-by-ranges-of-values/m-p/468872#M119814</link>
      <description>&lt;P&gt;Use PROC FORMAT, it's less typing&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example here:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://documentation.sas.com/?docsetId=proc&amp;amp;docsetVersion=9.4&amp;amp;docsetTarget=n19px1npxeydvhn1xx9acadcm0vv.htm&amp;amp;locale=en" target="_blank"&gt;http://documentation.sas.com/?docsetId=proc&amp;amp;docsetVersion=9.4&amp;amp;docsetTarget=n19px1npxeydvhn1xx9acadcm0vv.htm&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jun 2018 21:34:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Categorize-a-variable-by-ranges-of-values/m-p/468872#M119814</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-06-08T21:34:08Z</dc:date>
    </item>
    <item>
      <title>Re: Categorize a variable by ranges of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Categorize-a-variable-by-ranges-of-values/m-p/468874#M119815</link>
      <description>&lt;P&gt;That’s not going to work. Where do you groupings live? In your head, or in an Excel file? Can it be made into a data set? I strongly second the PROC FORMAT option, ideally driven by a data set from Excel or creating a table using cards/datalines.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have issues post your code and we’ll help you modify it.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jun 2018 21:37:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Categorize-a-variable-by-ranges-of-values/m-p/468874#M119815</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-06-08T21:37:29Z</dc:date>
    </item>
    <item>
      <title>Re: Categorize a variable by ranges of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Categorize-a-variable-by-ranges-of-values/m-p/468879#M119817</link>
      <description>&lt;P&gt;Bigger picture might not be relevant to this particular problem. However, just throwing it out there where it comes from, I have a very dirty insurance claim data. The working column 'proc_cd' for a procedure code is a melting pot of CPT, ICD-9 procedure and some suspicious codes looking even just like ICD-10 procedure code. I'm starting from the obvious to me which is not necessarily to be true or correct. I suspect cross section of flag="other" and width=4 to be ICD-9 procedure code. Because CPT takes more than 5 digits. Since I have it suspected for ICD-9 procedure code then I looked up ICD-9 codebook and trying to categorize it by its generic ranges. Categorizing it helps to weed out non ICD9 procedure code values since being 4 digit only doesn't define it be ICD-9 procedure code alone. Also available online. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.icd9data.com/2012/Volume3/default.htm" target="_blank"&gt;http://www.icd9data.com/2012/Volume3/default.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data x; set uniq_codes;
width=length(proc_cd); 
length flag $20; 
if prxMatch("/^\d{5}\s*$/o",omm_proc_cd) then flag = "CPT1";
else if prxMatch("/^\d{4}F\s*$/o",proc_cd) then flag = "CPT2";
else if prxMatch("/^\d{4}T\s*$/o",proc_cd) then flag = "CPT3";
else if prxMatch("/^V\d{4}\s*$/o",proc_cd) then flag = "VCODE";
else if prxMatch("/^E\d{4}\s*$/o",proc_cd) then flag = "ECODE";
else if prxMatch("/^D\d{4}\s*$/o",proc_cd) then flag = "DCODE";
else if prxMatch("/^Z\d{4}\s*$/o",proc_cd) then flag = "ZCODE";
else if prxMatch("/^T\d{4}\s*$/o",proc_cd) then flag = "TCODE";
else if prxMatch("/^\D{5}\s*$/o",proc_cd) then flag = "NON_DIG";
else flag="other";
if flag="other" and width=4 then flag="POTENTIAL_ICD9"; 
run; 

data x1; set x;
/*ICD-9 procedure code*/
if flag="other" and width=4 then output;
run;

proc freq data=x;
tables width*flag/norow nocol nocum nopercent missing;
run; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 Jun 2018 21:57:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Categorize-a-variable-by-ranges-of-values/m-p/468879#M119817</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2018-06-08T21:57:09Z</dc:date>
    </item>
    <item>
      <title>Re: Categorize a variable by ranges of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Categorize-a-variable-by-ranges-of-values/m-p/468880#M119818</link>
      <description>just added:&lt;BR /&gt;else if prxMatch("/^\d{4}\s*$/o",proc_cd) then flag = "ICD9";&lt;BR /&gt;else flag="other";</description>
      <pubDate>Fri, 08 Jun 2018 22:14:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Categorize-a-variable-by-ranges-of-values/m-p/468880#M119818</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2018-06-08T22:14:20Z</dc:date>
    </item>
    <item>
      <title>Re: Categorize a variable by ranges of values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Categorize-a-variable-by-ranges-of-values/m-p/468938#M119839</link>
      <description>&lt;P&gt;assuming i understand what youre asking, unfortunately i don't think there is a simpler way. If you look at sas macros that have been released for handling icd9 and icd10 codes they are incredibly longwinded and tedious eg see '&lt;A title="PMCA Version 2 Statistical Analysis System (SAS) Programming Code" href="http://www.seattlechildrens.org/zip/PMCA_Version_2_SAS_Programming_Code.zip" target="_blank"&gt;PMCA Version 2 Statistical Analysis System (SAS) Programming Code&lt;/A&gt;' here: &lt;A href="http://www.seattlechildrens.org/research/child-health-behavior-and-development/mangione-smith-lab/measurement-tools/" target="_blank"&gt;http://www.seattlechildrens.org/research/child-health-behavior-and-development/mangione-smith-lab/measurement-tools/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Jun 2018 18:26:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Categorize-a-variable-by-ranges-of-values/m-p/468938#M119839</guid>
      <dc:creator>pau13rown</dc:creator>
      <dc:date>2018-06-09T18:26:47Z</dc:date>
    </item>
  </channel>
</rss>

