DATA Step, Macro, Functions and more

Two digit month help

Accepted Solution Solved
Reply
Contributor
Posts: 73
Accepted Solution

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
Trusted Advisor
Posts: 1,611

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

View solution in original post


All Replies
Solution
‎11-17-2015 12:21 PM
Trusted Advisor
Posts: 1,611

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

Contributor
Posts: 73

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.

Trusted Advisor
Posts: 1,611

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.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 283 views
  • 0 likes
  • 2 in conversation