DATA Step, Macro, Functions and more

Date issue

Accepted Solution Solved
Reply
Super Contributor
Posts: 268
Accepted Solution

Date issue

Hi,

I have an issue with one of the datasets I am working on. The two date fields in my dataset are as below -

48

ELGBGNDT

Num

8

MMDDYY10.

34

ELIGDT

Num

8

MMDDYY10.

DATE9.

ELIGDT

When I run this code, I get back 0 records which I am not able to resolve.

data MHTST.MKTLVL_MBR_201112;

set MHTST.FINALMBR;

if eligdt='12/31/2011' then output;

run;

These are the values for the two variables in the sas dataset.

ELIGDT      ELGBGNDT

07/31/201107/01/2011
08/31/201108/01/2011
09/30/201109/01/2011
10/31/201110/01/2011
11/30/201111/01/2011
12/31/201112/01/2011

Any suggestions are appreciated.

Thanks,
saspert


Accepted Solutions
Solution
‎03-11-2013 11:47 AM
PROC Star
Posts: 7,364

Re: Date issue

add a d onto your if statement and stating the date in date9. format.  i.e.,

if eligdt='31dec2011'd then output;


Note: corrected suggestion after seeing the suggestion made by .

View solution in original post


All Replies
Solution
‎03-11-2013 11:47 AM
PROC Star
Posts: 7,364

Re: Date issue

add a d onto your if statement and stating the date in date9. format.  i.e.,

if eligdt='31dec2011'd then output;


Note: corrected suggestion after seeing the suggestion made by .

Occasional Contributor
Posts: 14

Re: Date issue

Hi saspert,

Please look at the below code and it will serve your purpose.

data a;

input date1 : mmddyy10. date2 : mmddyy10.;

format date1 date2 date9.;

datalines;

07/31/2011 07/01/2011

12/31/2011 12/01/2011

;

data b;

set a;

if date1='31dec2011'd then output;     // adding a 'd' is possible only with date9. date format and not with mmddyy date format.

run;

Note - In the above example i am reading  the nonstandard date value , sas stores date values in numeric format, then i am using format statement to convert the date value into a comparable format.

Let me know in case of any queries.

Thanks,

Ankit

☑ This topic is solved.

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

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