I'm working with a datetime variable, but I want to reduce it to at least a day/month/year variable, or preferably monthyear, so that I can then select only distinct cases of the reduced format. Basically, I want to recode the dates into season/year variables for many observations. However, the datepart() function doesn't seem to be working for me. The code I'm using is this, where raisedate is the original date variable: data want; data have; datetime = raisedate; format datetime dateampm.; datejulian = raisedate; format datejulian julian.; date = datepart(raisedate); run; Produces this: id raisedate datetime datejulian datepart 1 21AUG2014 01JAN60:05:32:36 AM 14233 0 2 27APR2017 01JAN60:05:48:56 AM 17117 0 3 21AUG2014 01JAN60:05:32:36 AM 14233 0 4 21AUG2014 01JAN60:05:32:36 AM 14233 0 5 21AUG2014 01JAN60:05:32:36 AM 14233 0 6 21AUG2014 01JAN60:05:32:36 AM 14233 0 7 21AUG2014 01JAN60:05:32:36 AM 14233 0 8 21AUG2014 01JAN60:05:32:36 AM 14233 0 9 12MAR2019 01JAN60:06:00:20 AM 19071 0 10 26APR2019 01JAN60:06:01:05 AM 19116 0 So, for some reason I can reformat the date time, but the datepart() function isn't working. Perhaps related to this issue, is that if I select distinct on the raisedate variable (i.e. without an id variable), I still get multiple indistinct entries, such as from above, even with the various formats broken out: 21AUG2014 01JAN60:05:32:36 AM 14233 0 21AUG2014 01JAN60:05:32:36 AM 14233 0 21AUG2014 01JAN60:05:32:36 AM 14233 0 21AUG2014 01JAN60:05:32:36 AM 14233 0 21AUG2014 01JAN60:05:32:36 AM 14233 0 21AUG2014 01JAN60:05:32:36 AM 14233 0 Clearly, they are not obviously distinct depending on format. I've ran into issues with lack of rounding hidden from user view before in SAS, but I'm not sure if that's the issue here, or how I would "round" a date to resolve it. Any recommendations for what to do? Many thanks!
... View more