data flag;
input custormerid 1-3 st_date $5-14 enddate $ 16-26;
format st_date DDMMYYS10. enddate DDMMYYS10.;
datalines;
001 01/01/2016 30/01/2016
002 02/02/2016 25/02/2016
003 05/03/2016 31/03/2016
004 06/04/2016 17/04/2016
005 08/05/2016 31/05/2016
006 09/06/2016 08/06/2016
007 11/07/2016 04/07/2016
008 12/08/2016 30/07/2016
009 13/09/2016 31/08/2016
010 15/10/2016 30/09/2016
;
run;
data endmonth;
set flag;
if enddate=intnx('month',enddate,0,'e') then flag='Yes';
else flag= 'No';
run;
I want flag variable which date is end of month Yes
which is not end of month NO
To use the INTNX() function and the DDMMYYS format with your variables you need to populate them with date values and not text strings.
So when reading the values from the source text using the DDMMYY informat.
input custormerid st_date :ddmmyy. enddate :ddmmyy. ;
Or use the INPUT() function in your testing for the end of the month.
if input(enddate,ddmmyy10.)=intnx('month',input(enddate,ddmmyy10.),0,'e') then flag='Yes';
To use the INTNX() function and the DDMMYYS format with your variables you need to populate them with date values and not text strings.
So when reading the values from the source text using the DDMMYY informat.
input custormerid st_date :ddmmyy. enddate :ddmmyy. ;
Or use the INPUT() function in your testing for the end of the month.
if input(enddate,ddmmyy10.)=intnx('month',input(enddate,ddmmyy10.),0,'e') then flag='Yes';
why we use input function
Use the INPUT statement if you are actually reading the data from text, like in your little example.
But if you already have a SAS dataset that has the date as a character variable then you need the INPUT() function call to convert those strings into actual date values. Or make a new version of the dataset that uses the INPUT() function to create a variable that has actual date values.
In addition to what @Tom said, save yourself some typing and prevent some potential typographical errors.
Use numeric 1 instead of 'Yes'
Use numeric 0 instead of 'No'
If necessary for clarity, you can assign a custom format to this 0/1 variable. In addition, the arithmetic mean of the 0/1 variable is the proportion of 1s.
Thank you paigemiller
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.