<?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: Subset data when Prxmatch condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Subset-data-when-Prxmatch-condition/m-p/375486#M90021</link>
    <description>&lt;P&gt;Solution out of macro. It helped only when list of condition to look up was short enough just to list in the code itself.&amp;nbsp;&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 x Main_Diagnosis Other_Diagnosis_1-Other_Diagnosis_24; 
do over list;
if x=list in :("P","C", "H"......) 
then a=1;
end;
if a=1 then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With macro and loop solution because I had looong list of diseases to eliminate from the dataset that would be too tedious ...&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import
 datafile="…\icd.csv" out=icd
 dbms=csv replace;
 getnames=yes;
run;

data icda(rename=(x=types_icd y=diseases_icd)); set icd;
 format y $10.;
  defect_original=diseases_icd;
 if diseases_icd ne " " then y="[*]"||diseases_icd;
 format x $10.;
  icd_new=compress(types_icd,'.');
  icd_original=types_icd;
  x="[*]"||icd_new;
 drop types_icd diseases_icd defect_original icd:;
 run;

proc sql noprint;
     select  diseases_icd
     into :diseases separated by '|'
     from  icda(where=(diseases_icd ne " "));
quit;

proc sql noprint;
   select  types_icd
     into :types separated by '|'
     from  icda;
quit;

%let x=:Other_Diagnosis_1 - :Other_Diagnosis_10;

data want; set have;       
icd_code = catx('*','*',Main_diagnosis, of Other_Diagnosis_Code:); 

if prxmatch("m/&amp;amp;types/oi",icd_code) &amp;gt; 0 and prxmatch("m/&amp;amp;diseases/oi",icd_code) = 0; /* types with no diseases */

run;
&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 12 Jul 2017 20:42:14 GMT</pubDate>
    <dc:creator>Cruise</dc:creator>
    <dc:date>2017-07-12T20:42:14Z</dc:date>
    <item>
      <title>Subset data when Prxmatch condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subset-data-when-Prxmatch-condition/m-p/375320#M89961</link>
      <description>&lt;P&gt;I'd like to eliminate patients with certain diseases from data "have" to a "want" using Prxmatch function. The list of ineligible diagnosis can be very long so reading the list in csv file was the option to go for me. I know for sure that HAVE data is supposed to keep almost all patients&amp;nbsp;into WANT data according to my&amp;nbsp;manual check. However, i keep getting LOG below saying no observations output into WANT. Btw, attached is the sample data. SAS data was not allowed so is exported to csv file to attach to this post.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Log:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOTE: There were 6477 observations read from the data set HAVE
NOTE: The data set WANT has 0 observations and 30 variables.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data icda(rename=(x=preterm_icd y=types_icd)); set icd;
 format y $10.;
  defect_original=types_icd;
 if types_icd ne " " then y="[*]"||types_icd;
 format x $10.;
  /*icd_new=compress(other_icd,'.');
  icd_original=other_icd;
  x="[*]"||icd_new;
 drop other_icd types_icd defect_original icd:;*/
 run;&lt;BR /&gt;&lt;BR /&gt;/*please ignore part commented out above. i left it just to show that there &lt;BR /&gt;was a step preceded to subset data using Prxmatch as well. Step 1 worked fine, no prob*/

proc sql noprint;
   select  types_icd
     into :types separated by '|'
     from  icda;
quit;

%put &amp;amp;types;
%let x=:Other_Diagnosis_Code_1 - :Other_Diagnosis_Code_10;

%macro loop(case);
%global case1;
%let case1=&amp;amp;case;
%if &amp;amp;case=all_types                  %then %let condition1 = &amp;amp;types;

data want; set have;
                
icd_code = catx('*','*',Principal_Diagnosis_Code, of Other_Diagnosis_Code:); 

if prxmatch("m/&amp;amp;condition1/oi",icd_code) = 0; 
source="Internal";
run;
%mend loop;
%loop(all_types);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions for a trouble shooting?&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2017 20:03:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subset-data-when-Prxmatch-condition/m-p/375320#M89961</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2017-07-12T20:03:16Z</dc:date>
    </item>
    <item>
      <title>Re: Subset data when Prxmatch condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subset-data-when-Prxmatch-condition/m-p/375325#M89963</link>
      <description>&lt;P&gt;There is a macro available to create data step code that you can paste here for example data. Unfortunately a simple CSV file does not necessarily tell us what varaible type you have assigned to specific variables plus we have to write code to read said data and may not have the time as volunteers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2017 14:27:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subset-data-when-Prxmatch-condition/m-p/375325#M89963</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-07-12T14:27:20Z</dc:date>
    </item>
    <item>
      <title>Re: Subset data when Prxmatch condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subset-data-when-Prxmatch-condition/m-p/375362#M89981</link>
      <description>Thanks, I will teach myself the content in the link. Will take me few hours. Thanks for response anyway.</description>
      <pubDate>Wed, 12 Jul 2017 15:16:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subset-data-when-Prxmatch-condition/m-p/375362#M89981</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2017-07-12T15:16:30Z</dc:date>
    </item>
    <item>
      <title>Re: Subset data when Prxmatch condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subset-data-when-Prxmatch-condition/m-p/375420#M90010</link>
      <description>Hi Ballardw, is there SAS version of creating sample data? I don't have a SAS studio.</description>
      <pubDate>Wed, 12 Jul 2017 17:13:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subset-data-when-Prxmatch-condition/m-p/375420#M90010</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2017-07-12T17:13:42Z</dc:date>
    </item>
    <item>
      <title>Re: Subset data when Prxmatch condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subset-data-when-Prxmatch-condition/m-p/375454#M90020</link>
      <description>&lt;P&gt;Just trouble shooted this problem. I will update the post with a solution when I get a chance.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2017 19:04:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subset-data-when-Prxmatch-condition/m-p/375454#M90020</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2017-07-12T19:04:01Z</dc:date>
    </item>
    <item>
      <title>Re: Subset data when Prxmatch condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subset-data-when-Prxmatch-condition/m-p/375486#M90021</link>
      <description>&lt;P&gt;Solution out of macro. It helped only when list of condition to look up was short enough just to list in the code itself.&amp;nbsp;&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 x Main_Diagnosis Other_Diagnosis_1-Other_Diagnosis_24; 
do over list;
if x=list in :("P","C", "H"......) 
then a=1;
end;
if a=1 then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With macro and loop solution because I had looong list of diseases to eliminate from the dataset that would be too tedious ...&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import
 datafile="…\icd.csv" out=icd
 dbms=csv replace;
 getnames=yes;
run;

data icda(rename=(x=types_icd y=diseases_icd)); set icd;
 format y $10.;
  defect_original=diseases_icd;
 if diseases_icd ne " " then y="[*]"||diseases_icd;
 format x $10.;
  icd_new=compress(types_icd,'.');
  icd_original=types_icd;
  x="[*]"||icd_new;
 drop types_icd diseases_icd defect_original icd:;
 run;

proc sql noprint;
     select  diseases_icd
     into :diseases separated by '|'
     from  icda(where=(diseases_icd ne " "));
quit;

proc sql noprint;
   select  types_icd
     into :types separated by '|'
     from  icda;
quit;

%let x=:Other_Diagnosis_1 - :Other_Diagnosis_10;

data want; set have;       
icd_code = catx('*','*',Main_diagnosis, of Other_Diagnosis_Code:); 

if prxmatch("m/&amp;amp;types/oi",icd_code) &amp;gt; 0 and prxmatch("m/&amp;amp;diseases/oi",icd_code) = 0; /* types with no diseases */

run;
&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2017 20:42:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subset-data-when-Prxmatch-condition/m-p/375486#M90021</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2017-07-12T20:42:14Z</dc:date>
    </item>
  </channel>
</rss>

