Dear Friends, I am quite new to SAS. I am struggling to write a code in SAS. Objective - Collapse the daily data on return into average of daily return in each quarter end date like 31-Mar-2001, 30-Jun-2001,30-Sep-2001..... for each company. Other Details - There are multiple returns in a single date for a company and there will be many dates which will not be there in the dataset. The program should take the average of all these returns for each company and in the output datafile, it should show only the quarter end dates with the average (daily) return in that quarter. The data runs into millions so it will be difficult to share (sample is in the table below). In the output, I need these 3 columns but dates should be only the end date of each quarter as shown in the output table below: Required Output Table: Date Company Id Return (Average of all Daily Returns across the given quarter) 31/03/2001 xyz 2% 30/06/2001 xyz 1.38% 30/09/2001 xyz 1.29% 31/12/2001 xyz 3.01% .... .... ... 31/03/2010 xyz 1.45% 30/06/2010 xyz 3% 30/09/2010 xyz 2.12% 31/12/2010 xyz 2.07% .... 31/03/2001 abc 0.99% 30/06/2001 abc 1.75% 30/09/2001 abc 1.67% 31/12/2001 abc 2.01% ... .... 31/03/2011 abc 3% 30/06/2011 abc 1.23% 30/09/2011 abc 2% 31/12/2011 abc 1.3% ... ... ... Input Data Sample - Date Company Id Daily Return 01/01/2001 abc 1.1% 01/01/2001 abc 1.23% 01/01/2001 abc 0.67% 02/01/2001 abc .89% 02/01/2001 abc 1.02% 05/02/2001 abc 1% 06/02/2001 abc 0.99% 06/02/2001 abc 2% ...... ... .... 23/07/2010 abc 1.34% ..... 10/01/2003 xyz 2.3% 10/01/2003 xyz 1.87% ... ... ... 28/06/2009 xyz 3% 02/07/2009 xyz 1.2% 02/07/2009 xyz 0.59% ..... ... ... 30/09/2009 xyz 1.23% 04/10/2009 xyz 2%
... View more
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.
... View more
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
... View more
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;
... View more