The data used ('test') is created directly within the script via a DATA step and the DATALINES statement. There is no dependency on external data sources or default SAS libraries like SASHELP for input data.
1 Code Block
DATA STEP Data
Explanation : This DATA STEP block creates a dataset named 'test'. It defines a 'date' variable, applies the INFORMAT (for reading) and FORMAT (for display) 'date9.' formats to it, and then populates it with date values specified via the DATALINES statement. This dataset serves as an example for testing the FCMP functions.
Copied!
data test;
input date;
informat date date9.;
format date date9.;
datalines;
31DEC2016
01JAN2017
15FEB2017
15FEB2016
08JAN2017
09JAN2017
25DEC2017
31DEC2017
01JAN2018
05JAN2017
05APR2017
09JUL2017
10NOV2017
31DEC2017
15MAR2017
;
run;
1
DATA test;
2
INPUT date;
3
informat date date9.;
4
FORMAT date date9.;
5
DATALINES;
6
31DEC2016
7
01JAN2017
8
15FEB2017
9
15FEB2016
10
08JAN2017
11
09JAN2017
12
25DEC2017
13
31DEC2017
14
01JAN2018
15
05JAN2017
16
05APR2017
17
09JUL2017
18
10NOV2017
19
31DEC2017
20
15MAR2017
21
;
22
RUN;
2 Code Block
PROC FCMP
Explanation : This PROC FCMP procedure defines a user-defined function named 'BeginMonth'. The function takes a 'DateDay' argument (a numeric SAS date) and uses SAS's INTNX function to calculate the beginning of the month date ('b') corresponding to 'DateDay', with no offset ('0'). The function is stored in the 'work.cat_function.test' catalog and returns the first day of the month.
Explanation : This PROC FCMP procedure defines a user-defined function named 'EndMonth'. Similar to 'BeginMonth', it takes a 'DateDay' argument and uses INTNX to calculate the end of the month date ('e') corresponding to 'DateDay', with no offset. The function is also stored in the 'work.cat_function.test' catalog and returns the last day of the month.
Explanation : This DATA STEP block reads the existing 'test' dataset. It adds two new variables, 'FirstDay' and 'LastDay', and applies the 'date9.' format to them. Then, it calls the previously defined FCMP functions 'BeginMonth' and 'EndMonth', passing them the 'date' variable to calculate the first and last day of each month, respectively. The results are stored in the new variables of the 'test' dataset.
Copied!
data test;
set test;
format FirstDay lastDay DATE9.;
FirstDay=BeginMonth(date);
LastDay=EndMonth(date);
run;
1
DATA test;
2
SET test;
3
FORMAT FirstDay lastDay DATE9.;
4
FirstDay=BeginMonth(date);
5
LastDay=EndMonth(date);
6
RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : Creation date : 14/04/2017 (en)
Last update : 14/04/2017 (en)
Author(s) : Nicolas DUPONT
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.