DATA Step, Macro, Functions and more

Subset data when Prxmatch condition

Reply
Frequent Contributor
Posts: 143

Subset data when Prxmatch condition

[ Edited ]

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 into WANT data according to my 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. 

 

Log:

NOTE: There were 6477 observations read from the data set HAVE
NOTE: The data set WANT has 0 observations and 30 variables.

 

Code:

 

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;

/*please ignore part commented out above. i left it just to show that there
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 &types; %let x=:Other_Diagnosis_Code_1 - :Other_Diagnosis_Code_10; %macro loop(case); %global case1; %let case1=&case; %if &case=all_types %then %let condition1 = &types; data want; set have; icd_code = catx('*','*',Principal_Diagnosis_Code, of Other_Diagnosis_Code:); if prxmatch("m/&condition1/oi",icd_code) = 0; source="Internal"; run; %mend loop; %loop(all_types);

 

Any suggestions for a trouble shooting?

Thanks.

Super User
Posts: 11,343

Re: Subset data when Prxmatch condition

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.

 

Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... 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.

Frequent Contributor
Posts: 143

Re: Subset data when Prxmatch condition

Thanks, I will teach myself the content in the link. Will take me few hours. Thanks for response anyway.
Frequent Contributor
Posts: 143

Re: Subset data when Prxmatch condition

Hi Ballardw, is there SAS version of creating sample data? I don't have a SAS studio.
Frequent Contributor
Posts: 143

Re: Subset data when Prxmatch condition

Just trouble shooted this problem. I will update the post with a solution when I get a chance. 

Frequent Contributor
Posts: 143

Re: Subset data when Prxmatch condition

[ Edited ]

Solution out of macro. It helped only when list of condition to look up was short enough just to list in the code itself. 

 

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;

 

With macro and loop solution because I had looong list of diseases to eliminate from the dataset that would be too tedious ...

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/&types/oi",icd_code) > 0 and prxmatch("m/&diseases/oi",icd_code) = 0; /* types with no diseases */

run;

 

 

Ask a Question
Discussion stats
  • 5 replies
  • 83 views
  • 1 like
  • 2 in conversation