BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
G_I_Jeff
Obsidian | Level 7

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. 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

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
G_I_Jeff
Obsidian | Level 7

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.

PaigeMiller
Diamond | Level 26

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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