I am taking an Udemy advanced SAS course. An exercise for the PROC SQL has me doing two PROC IMPORTS and then a PROC SQL using the ON clause.
In the first part of the attached code I have the process working. The import and SQL are only using partial dataset names (that is: phd0 or pag0) where I like to use full names even for work datasets so I have 'Work.Patient_HD' and 'Work.Patient_Age.' In the ON statement when I have the dataset names of 'Work.Patient_HD.Patient_id' the proc fails with:
/* Coding exercise 27 for SQL */
/* The below works */
proc import datafile = '/home/lcwrite/data/Patient_HD.xlsx'
dbms=xlsx
out = phd0;
run;
proc import datafile = '/home/lcwrite/data/Patient_age_gender.xlsx'
dbms=xlsx
out = pag0;
run;
proc sql feedback;
select *
from phd0, pag0
where phd0.Patient_ID = pag0.Patient_ID
;
quit;
proc sql feedback;
select *
from phd0 INNER JOIN
pag0
on phd0.Patient_id = pag0.Patient_id
order by Patient_ID;
quit;
/* ------------------------------------------------------------------------------------------------------------------- */
/* The below does not work */
proc import datafile = '/home/lcwrite/data/Patient_HD.xlsx'
dbms=xlsx
out = Work.Patient_HD;
run;
proc import datafile = '/home/lcwrite/data/Patient_age_gender.xlsx'
dbms=xlsx
out = Work.Patient_AGE;
run;
proc sql feedback;
select *
from Work.Patient_HD, Work.Patient_AGE
where Work.Patient_HD.Patient_ID = Work.Patient_AGE.Patient_ID
;
quit;
/* The error 22 points to the decimal in 'Work.Patient_HD.Patient_id' */
An SQL table reference alias cannot contain a period. If you use a two level dataset name
from libref.memname
then only the member part is used to set the default alias.
Either use the alias that SAS will understand,
from libref.mem1
where mem1.var1 is not null
or assign your own.
from libref.mem1 alias
where alias.var1 is not null
An SQL table reference alias cannot contain a period. If you use a two level dataset name
from libref.memname
then only the member part is used to set the default alias.
Either use the alias that SAS will understand,
from libref.mem1
where mem1.var1 is not null
or assign your own.
from libref.mem1 alias
where alias.var1 is not null
From now on, when you have an error in a PROC, show us the log for that PROC. We need to see the code as it appears in the log, and any messages such as errors, warnins and noes. DO NOT show us just the error messages in the log, detached from the code in the log.
where Work.Patient_HD.Patient_ID = Work.Patient_AGE.Patient_ID
;
Try
where patient_hd.patient_id =patient_age.patient_id;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.