## Two digit month help

Solved
Frequent Contributor
Posts: 75

# Two digit month help

[ Edited ]

I have a comma delimited file that the first 4 bytes are MMDD. I'm trying to accomplish the following:

```DATA COM01;
INFILE INPT;
INPUT @01 MONTH   2.
@03 DAY     2.
@06 HOUR    2.
@10 APPLID  \$8.
@55 RESP    11.3;
PMONTH = INTNX('MONTH', TODAY(), -1);
FORMAT PMONTH MONTH2.;
IF MONTH = PMONTH;
KEEP MONTH DAY HOUR APPLID RESP;
RUN;```

Yet I get 0 rows selected. If I print out the results I see both months equal the same value. I'm not sure what is wrong. I've played with some formatting but that hasn't gotten me the results I expect.

Accepted Solutions
Solution
‎11-17-2015 12:21 PM
Posts: 3,055

## Re: Two digit month help

[ Edited ]

PMONTH is a SAS Date value. The fact that you have applied a SAS format to it is irrelevant here, that only changes the way the value of PMONTH is displayed, it does not change the fact that the actual value of PMONTH is a SAS date value.

MONTH is an integer 1 through 12.

So, they will never match. A SAS date value will not match an integer 1 through 12 (* — unless the actual date is Jan 1, 1960 through Jan 12,1960 and I don't think we are talking about those dates)

Perhaps you want

if month=month(pmonth);

--
Paige Miller

All Replies
Solution
‎11-17-2015 12:21 PM
Posts: 3,055

## Re: Two digit month help

[ Edited ]

PMONTH is a SAS Date value. The fact that you have applied a SAS format to it is irrelevant here, that only changes the way the value of PMONTH is displayed, it does not change the fact that the actual value of PMONTH is a SAS date value.

MONTH is an integer 1 through 12.

So, they will never match. A SAS date value will not match an integer 1 through 12 (* — unless the actual date is Jan 1, 1960 through Jan 12,1960 and I don't think we are talking about those dates)

Perhaps you want

if month=month(pmonth);

--
Paige Miller
Frequent Contributor
Posts: 75

## Re: Two digit month help

Thank you!

For some reason I can never wrap my head around the formatting. I even performed a PROC CONTENTS against the file and looked at that.

Posts: 3,055

## Re: Two digit month help

When performing a comparison of two values, don't use formats, don't look at formats, ignore the formats. The only thing that will be compared are the unformatted values.

--
Paige Miller
🔒 This topic is solved and locked.