BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BrahmanandaRao
Lapis Lazuli | Level 10
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

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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';

View solution in original post

5 REPLIES 5
Tom
Super User Tom
Super User

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';
BrahmanandaRao
Lapis Lazuli | Level 10

why we use input function 

Tom
Super User Tom
Super User

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.

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
BrahmanandaRao
Lapis Lazuli | Level 10

Thank you paigemiller

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 672 views
  • 0 likes
  • 3 in conversation