The G codes ('G11','G111','G1110') are potential values in each of three variables/columns: primary, secondary, and tertiary. The 3 columns (primary, secondary, tertiary) in csv file are separate. I want to create a new dataset by selecting observations with these G codes in variables: primary, secondary, and tertiary. The code below with the use "OR" does not work. How do I go about this? Thanks.
Data tricolumns;
set EDPh;
if Primary Diagnosis in ('G11','G111','G1110') OR secondary Diagnosis in ('G11','G111','G1110') OR tertiary Diagnosis in ('G11','G111','G1110') ;
run;
That code would work if you used valid variable names.
So either use variable names that follow the rules (only contain digits letters or undescore and do not start with a digit).
if PrimaryDiagnosis in ('G11','G111','G1110')
OR secondaryDiagnosis in ('G11','G111','G1110')
OR tertiaryDiagnosis in ('G11','G111','G1110')
;
Of if you have the VALIDVARNAME option set to ANY then use a name literal to reference those non-standard names.
if 'Primary Diagnosis'n in ('G11','G111','G1110')
OR 'secondary Diagnosis'n in ('G11','G111','G1110')
OR 'tertiary Diagnosis'n in ('G11','G111','G1110')
;
Hi Tom, it worked, thank you.
If you require the G codes in any of the three diagnoses then the OR is correct.
If you require all three diagnosis to have a G value then the condition should be AND
Thanks, Reeza. I require the G codes in any of the three diagnoses.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.