BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
femiajumobi1
Quartz | Level 8

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; 

1 ACCEPTED SOLUTION

Accepted Solutions
5 REPLIES 5
Tom
Super User Tom
Super User

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') 
;
Reeza
Super User
You should mark Tom's solution as the correct one, not your own response. You can unselect yours and then select his I believe.
Reeza
Super User

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

femiajumobi1
Quartz | Level 8

Thanks, Reeza. I require the G codes in any of the three diagnoses.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 5 replies
  • 503 views
  • 2 likes
  • 3 in conversation