I have the following code where I use proc sql to identify readmits from claim data:
PROC SQL;
Create Table all.readmits2 as
Select A.uidnum, A.DISD label = "Previous Discharge Date",
B.ADMD label = "Admission Date",
B.ADMD-A.DISD as Gap, 1 as Tag
From all.hssc_ub__shp_visits_match as A join all.hssc_ub__shp_visits_match as B
On A.uidnum = B.uidnum
Where
B.ADMD-A.DISD between 1 and 30;
Quit;
The coding works well and I am able to identify the approiate 30 day readmits however, I would like to include important demographic/utlization variables in my sql table (all_sex, all_age, all_race, all_race2, cond3, all_ip, all_ed, all_op, all_setting,). When I try to inculde these additional variables, I run into issues.
I used the following code and recieved the error message posted below:
PROC SQL;
Create Table all.readmits4 as
Select A.uidnum, all_sex, all_age, all_race, all_race2, cond3, all_ip, all_ed, all_op, all_setting,
A.DISD label = "Previous Discharge Date",
B.ADMD label = "Admission Date",
B.ADMD-A.DISD as Gap, 1 as Tag,
From all.hssc_ub__shp_visits_match as A join all.hssc_ub__shp_visits_match as B
On A.uidnum = B.uidnum
Where
B.ADMD-A.DISD between 1 and 30;
Quit;
Error Message:
199 From all.hssc_ub__shp_visits_match as A join all.hssc_ub__shp_visits_match as B
--- ----
22 76
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, (, *, **, +, ',', -, /,
<, <=, <>, =, >, >=, ?, AND, BETWEEN, CONTAINS, EQ, EQT, FROM, GE, GET, GT, GTT,
LE, LET, LIKE, LT, LTT, NE, NET, OR, ^=, |, ||, ~=.
ERROR 76-322: Syntax error, statement will be ignored.
199! From all.hssc_ub__shp_visits_match as A join all.hssc_ub__shp_visits_match as B
----
22
ERROR 22-322: Syntax error, expecting one of the following: a quoted string, ',', AS, FORMAT,
FROM, INFORMAT, INTO, LABEL, LEN, LENGTH, TRANSCODE.
How can Inculde the additional variables in my SQL table?
Thanks,
Since those variables are in table A and B (reflexive joins are like that) prefix your "all" variables with A. just like you did for A.uidnum.
A.all_sex, A.all_age etc.
I'm not a SQL expert, but I think it's useful to have another pair of eyes here. Standard SQL syntax would remove the comma between Tag and From.
Since those variables are in table A and B (reflexive joins are like that) prefix your "all" variables with A. just like you did for A.uidnum.
A.all_sex, A.all_age etc.
Well, now that the first error is gone we can move on to the next one. These messages are telling you (for example) that ALL_SEX is in both of your incoming data sets. Which one do you want to select, the one in A or the one in B? Your program has to specify that. So instead of:
select all_sex,
You need to specify one of these:
select A.all_sex,
select B.all_sex,
You not only can choose, but you have to choose.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.