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.
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.
Just trouble shooted this problem. I will update the post with a solution when I get a chance.
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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.