BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
wheddingsjr
Pyrite | Level 9

Hello all. I am getting the above mentioned Error and I am not sure why. I have read quite a few answers to others with this error but they weren't comparable to mine. The query is:

PROC SQL;
CREATE TABLE work.patient_cohort_w_Race AS
SELECT DISTINCT pc.*

	,CASE WHEN PatientRaceDSC = 'ASIAN' THEN 'Asian'
		  WHEN PatientRaceDSC = 'BLACK OR AFRICAN AMERICAN' THEN 'Black or African American'
		  WHEN PatientRaceDSC = 'Hispanic or Latino' THEN 'Hispanic or Latino'
		  WHEN PatientRaceDSC LIKE ('WHITE%') THEN 'White or Caucasian'
		  WHEN PatientRaceDSC = 'American Indian or Alaska Native' THEN 'American Indian or Alaska Native'
		  WHEN PatientRaceDSC = 'Native Hawaiian or Other Pacific Islander' THEN 'Native Hawaiian or Other Pacific Islander'
	 	  WHEN PatientRaceDSC IN ('Declined', 'Unavailable') THEN 'Unknown'
		  WHEN PatientRaceDSC IS NULL THEN 'Unknown'
		  ELSE 'Other' END AS RACE
	, CASE WHEN EthnicGroupDSC in ('Yes Hispanic','Hispanic') THEN 'YES' 
	      ELSE 'NO' END AS HISPANIC_LATINO

FROM Fin.HospitalAccount HA 	
LEFT JOIN work.patient_cohort pc on HA.PatientID = pc.PatientID
LEFT JOIN pat.Race R on HA.PatientID = R.PatientID
LEFT JOIN pat.Patient P on HA.PatientID = P.PatientID

and this is the log with the error:

274  PROC SQL;
     ----
     78
ERROR 78-322: Expecting a ','.

275  CREATE TABLE work.patient_cohort_w_Race AS
276  SELECT DISTINCT pc.*
277
278      ,CASE WHEN PatientRaceDSC = 'ASIAN' THEN 'Asian'
279            WHEN PatientRaceDSC = 'BLACK OR AFRICAN AMERICAN' THEN 'Black or African American'
280            WHEN PatientRaceDSC = 'Hispanic or Latino' THEN 'Hispanic or Latino'
281            WHEN PatientRaceDSC LIKE ('WHITE%') THEN 'White or Caucasian'
282            WHEN PatientRaceDSC = 'American Indian or Alaska Native' THEN 'American Indian or
282! Alaska Native'
283            WHEN PatientRaceDSC = 'Native Hawaiian or Other Pacific Islander' THEN 'Native
283! Hawaiian or Other Pacific Islander'
284            WHEN PatientRaceDSC IN ('Declined', 'Unavailable') THEN 'Unknown'
285            WHEN PatientRaceDSC IS NULL THEN 'Unknown'
286            ELSE 'Other' END AS RACE
287      , CASE WHEN EthnicGroupDSC in ('Yes Hispanic','Hispanic') THEN 'YES'
288            ELSE 'NO' END AS HISPANIC_LATINO
289
290  FROM Fin.HospitalAccount HA
291  LEFT JOIN work.patient_cohort pc on HA.PatientID = pc.PatientID
292  LEFT JOIN pat.Race R on HA.PatientID = R.PatientID
293  LEFT JOIN pat.Patient P on HA.PatientID = P.PatientID
1 ACCEPTED SOLUTION

Accepted Solutions
wheddingsjr
Pyrite | Level 9

Thanks @Reeza @PaigeMiller and @Tom 

 

I was able to figure it out and everything ran fine. Thanks for your heads ups and suggestions.

View solution in original post

13 REPLIES 13
PaigeMiller
Diamond | Level 26

The error in your code is before PROC SQL;

--
Paige Miller
wheddingsjr
Pyrite | Level 9

Thanks @PaigeMiller 

I sent the message to disregard my question because I figured it out and didn't know that you had already replied. The issue was that I didn't include 'quit;' to the end of the query. But now that creates another issue. I brought the code in from SQL and it runs. The PatientRaceDSC and the EthnicGroupDSC columns are created, however, they are not populating correctly. The rows in the PatientRaceDSC are all populated with 'UNKNOWN' and all the rows in the EthnicGroupDSC are all populated with 'NO' but that cant be so. I researched the CASE expression and it seems to be written correctly (I Think). I believe I have all the joins correct as well. Do you have any thoughts on what could be wrong?

Tom
Super User Tom
Super User

You seem to be having a hard time describing your issue.

Do you mean that in one or more of your generated datasets that some of the variables are getting set to UNKNOWN for every observation?

 

If so you need to look at the values that the variables you used in the calculations had.  

You could start with doing a PROC FREQ on the input datasets for the variables used in the calculation.

proc freq data=pat.Race;
  tables PatientRaceDSC  / list missing;
run;

 

But you might not see the problem there as it might be the issue is in the joining.  You can check that better by including the input variables into the output dataset. 

CREATE TABLE work.patient_cohort_w_Race AS
SELECT DISTINCT pc.*,r.PatientRaceDSC  
....

Then you can check the values actually used in the calculations.

Reeza
Super User
Error is before this code.
If you cannot find it, restart your system to clear any left over bugs and run it all again and see if it errors out. If it does, post the code immediately before this as well.
wheddingsjr
Pyrite | Level 9

Thanks @Reeza

 

I discovered the issue, but that just created a new one. Please see the reply to @PaigeMiller. Any insight on this would be greatly appreciated.

 

Thanks

Reeza
Super User
Please show the output from a PROC FREQ on the PatientRaceDSC column. You didn't prefix it so not sure what table it's from.

Following may also be useful:

proc freq data=patient_cohort_w_Race;
table PatientRaceDSC*Race / list missing;
run;
wheddingsjr
Pyrite | Level 9

@Reeza

 

This is the results from the proc freq data=patient_cohort_w_Race; you suggested

 

671  proc freq data=patient_cohort_w_Race;
672  table PatientRaceDSC*Race / list missing;
ERROR: Variable PATIENTRACEDSC not found.
673  run;
PaigeMiller
Diamond | Level 26

This means you do not have a variable name PATIENTRACEDSC in data set PATIENT_COHORT_W_RACE. If you disagree with this error message, then show us PROC CONTENTS for data set PATIENT_COHORT_W_RACE.

--
Paige Miller
wheddingsjr
Pyrite | Level 9

Hi @PaigeMiller 

I am creating the PATIENT_COHORT_W_RACE table so it doesn't exist yet. I realized that I didnt have the aliases for the tables they variable does exist in and added them. I get the same results. Here is the code that creates the work.patient_cohort table which works fine:

PROC SQL;
CREATE TABLE work.patient_cohort AS
SELECT DISTINCT a.mrn
	, a.PatientNM
	, a.dob
	, a.payorNM
	, scan(a.patientnm,1,',') as lastname
	, scan(a.patientnm, 2, ',') as firstname
	, a.SubscriberID as InsuredsIDNumber
	, a.firstDt as cohort_entering_Date
	, a.planID
	, a.PayorID
	,COMPRESS(SubscriberID, '', 'kd') AS EditedInsuredsIDNumber

FROM work.dataPull_2 a 
	INNER JOIN work.cntByMRN b
		ON a.mrn= b.mrn
	WHERE 
/*	 payornm like '%HARVARD PILGRIM%' /*' reporting period*/
	 payorID = 110001
/*and *PayorID IN (170001);*TUFTS HEALTH PLAN*/

;QUIT;

Now I want to add the Race and the Ethnicity variable by creating the work.patient_cohort_w_Race table:

PROC SQL;
CREATE TABLE work.patient_cohort_w_Race AS
SELECT DISTINCT pc.*

	,CASE WHEN r.PatientRaceDSC  = 'ASIAN' THEN 'Asian'
		  WHEN r.PatientRaceDSC = 'BLACK OR AFRICAN AMERICAN' THEN 'Black or African American'
		  WHEN r.PatientRaceDSC = 'Hispanic or Latino' THEN 'Hispanic or Latino'
		  WHEN r.PatientRaceDSC LIKE ('WHITE%') THEN 'White or Caucasian'
		  WHEN r.PatientRaceDSC = 'American Indian or Alaska Native' THEN 'American Indian or Alaska Native'
		  WHEN r.PatientRaceDSC = 'Native Hawaiian or Other Pacific Islander' THEN 'Native Hawaiian or Other Pacific Islander'
	 	  WHEN r.PatientRaceDSC IN ('Declined', 'Unavailable') THEN 'Unknown'
		  WHEN r.PatientRaceDSC IS NULL THEN 'Unknown'
		  ELSE 'Other' END AS RACE
	, CASE WHEN p.EthnicGroupDSC in ('Yes Hispanic','Hispanic') THEN 'YES' 
	      ELSE 'NO' END AS HISPANIC_LATINO

FROM work.patient_cohort pc	
LEFT JOIN pat.Identity I on pc.MRN = I.PatientIdentityID
LEFT JOIN pat.Race R on I.PatientIdentityID = R.PatientID
LEFT JOIN pat.Patient P on I.PatientIdentityID = P.PatientID
;quit;

 

PaigeMiller
Diamond | Level 26

I specifically asked to see the PROC CONTENTS output for data set PATIENT_COHOR_W_RACE. Please show us that.

 

Also, when debugging code like this, show us the LOG, not the code. Thanks.

--
Paige Miller
Reeza
Super User
PROC SQL;
CREATE TABLE work.patient_cohort_w_Race AS
SELECT DISTINCT pc.*,
r.PatientRaceDSC,

	,CASE WHEN r.PatientRaceDSC  = 'ASIAN' THEN 'Asian'
		  WHEN r.PatientRaceDSC = 'BLACK OR AFRICAN AMERICAN' THEN 'Black or African American'
		  WHEN r.PatientRaceDSC = 'Hispanic or Latino' THEN 'Hispanic or Latino'
		  WHEN r.PatientRaceDSC LIKE ('WHITE%') THEN 'White or Caucasian'
		  WHEN r.PatientRaceDSC = 'American Indian or Alaska Native' THEN 'American Indian or Alaska Native'
		  WHEN r.PatientRaceDSC = 'Native Hawaiian or Other Pacific Islander' THEN 'Native Hawaiian or Other Pacific Islander'
	 	  WHEN r.PatientRaceDSC IN ('Declined', 'Unavailable') THEN 'Unknown'
		  WHEN r.PatientRaceDSC IS NULL THEN 'Unknown'
		  ELSE 'Other' END AS RACE
	, CASE WHEN p.EthnicGroupDSC in ('Yes Hispanic','Hispanic') THEN 'YES' 
	      ELSE 'NO' END AS HISPANIC_LATINO

FROM work.patient_cohort pc	
LEFT JOIN pat.Identity I on pc.MRN = I.PatientIdentityID
LEFT JOIN pat.Race R on I.PatientIdentityID = R.PatientID
LEFT JOIN pat.Patient P on I.PatientIdentityID = P.PatientID
;quit;

proc freq data=patient_cohort_w_Race ;
table PatientRaceDSC*Race / list missing;
run;

Post the results from the result tab and the log.

 

 

wheddingsjr
Pyrite | Level 9
{lease disregard. I found my issue
wheddingsjr
Pyrite | Level 9

Thanks @Reeza @PaigeMiller and @Tom 

 

I was able to figure it out and everything ran fine. Thanks for your heads ups and suggestions.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 13 replies
  • 1203 views
  • 0 likes
  • 4 in conversation