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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 371 views
  • 2 likes
  • 3 in conversation