I am quite new to SAS. I am trying to import a daily frequency dataset (via left join) into another dataset which has quarterly frequency data. The daily data has multiple observations in a single day.
I have written the below code but I am getting the error - "ERROR 78-322: Expecting a ','.
proc sql;
create table Try.finalmerge as
select distinct a.*, mean(b.ret5y) as ret_5y_qtr_mean /* calculate the average return*/,
N(b.ret5y) as ret_5Y_qtr_count /* count the no of obs for return within a quarter */
from Try.file1 a left join Try.file2 b
on a.Code = b.Code /* same firm*/ and a.Date < b.Date and intnx('month', a.Date, 3, 'E') >= b.Date
/* this condition requires that the obs in the file2 data file should have the date greater than the date in file1 data (quarter end date)
and the date less than or equal to the end of the next quarter */
group by a.Code, a.Date /* calculate the average and count for ret for each code in each year-quarter */
order by a.Code, a.Date ; /* sorting*/
quit;
Please copy/paste the whole log from that step into a window opened with the </> button.
I second what @yabwon said. Remove the code from the "left join" keywords to the ON condition, and retype it.
The SAS System 17:16 Thursday, September 17, 2020 1 ;*';*";*/;quit;run; 2 OPTIONS PAGENO=MIN; 3 %LET _CLIENTTASKLABEL='Program'; 4 %LET _CLIENTPROCESSFLOWNAME='Process Flow'; 5 %LET _CLIENTPROJECTPATH=''; 6 %LET _CLIENTPROJECTPATHHOST=''; 7 %LET _CLIENTPROJECTNAME=''; 8 %LET _SASPROGRAMFILE=''; 9 %LET _SASPROGRAMFILEHOST=''; 10 11 ODS _ALL_ CLOSE; 12 OPTIONS DEV=PNG; 13 GOPTIONS XPIXELS=0 YPIXELS=0; 14 FILENAME EGSR TEMP; 15 ODS tagsets.sasreport13(ID=EGSR) FILE=EGSR 16 STYLE=HTMLBlue 17 STYLESHEET=(URL="file:///C:/Program%20Files/SASHome/SASEnterpriseGuide/7.1/Styles/HTMLBlue.css") 18 NOGTITLE 19 NOGFOOTNOTE 20 GPATH=&sasworklocation 21 ENCODING=UTF8 22 options(rolap="on") 23 ; NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR 24 25 GOPTIONS ACCESSIBLE; 26 libname Thesis1 "D:\Thesis Data\Pilot Data\Thesis Paper 1"; NOTE: Libref THESIS1 was successfully assigned as follows: Engine: V9 Physical Name: D:\Thesis Data\Pilot Data\Thesis Paper 1 26 ! /* Insert custom code before submitted code here */ 27 28 proc sql; 29 create table Try.finalmerge as 30 select distinct a.*, mean(b.ret5y) as ret_5y_qtr_mean /* calculate the average return*/, 31 N(b.ret5y) as ret_5Y_qtr_count /* count the no of obs for return within a quarter */ 32 from Try.file1 a left join Try.file2 b _ 78 ERROR 78-322: Expecting a ','. 33 on a.Code = b.Code /* same firm*/ and a.Date < b.Date and intnx('month', a.Date, 3, 'E') >= b.Date 34 /* this condition requires that the obs in the ret data file should have the date greater than the date in climate change 34 ! data (quarter end date) 35 and the date less than or equal to the end of the next quarter */ 36 group by a.Code, a.Date /* calculate the average and count for ret for each code in each year-quarter */ order by a.Code, a.Date ; /* sorting*/ 38 quit; NOTE: The SAS System stopped processing this step because of errors. NOTE: PROCEDURE SQL used (Total process time): real time 0.00 seconds cpu time 0.00 seconds 39 2 The SAS System 17:16 Thursday, September 17, 2020 40 41 GOPTIONS NOACCESSIBLE; 42 %LET _CLIENTTASKLABEL=; 43 %LET _CLIENTPROCESSFLOWNAME=; 44 %LET _CLIENTPROJECTPATH=; 45 %LET _CLIENTPROJECTPATHHOST=; 46 %LET _CLIENTPROJECTNAME=; 47 %LET _SASPROGRAMFILE=; 48 %LET _SASPROGRAMFILEHOST=; 49 50 ;*';*";*/;quit;run; 51 ODS _ALL_ CLOSE; 52 53 54 QUIT; RUN; 55
did you tried with adding `AS`
from Try.file1 AS a left join Try.file2 AS b
?
Bart
I tried that as well but I get new errors in that case -
ERROR 22-322: Syntax error, expecting one of the following: ;, ',', ANSIMISS, CROSS, EXCEPT, FULL, GROUP, HAVING, INNER, INTERSECT,
JOIN, LEFT, NATURAL, NOMISS, ORDER, OUTER, RIGHT, UNION, WHERE.
ERROR 201-322: The option is not recognized and will be ignored.
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!
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.