BookmarkSubscribeRSS Feed
Lani
Calcite | Level 5
I have a column named "EffectiveDate". I want to check for a record that has an EffectiveDate of "01-01-2010", then this record need to be removed. I don't know how to compare since the EffectiveDate is formated in Date type and the values look numerics. Can I use put function to convert the EffectiveDate to string? then I compare it with "01-01-2010". Your inputs are much appreciated.
3 REPLIES 3
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Suggestion: you need not post in more than one SAS discussion forum.

Scott Barry
SBBWorks, Inc.
SSN_Ravi
Calcite | Level 5
Hi Lani,

Yes, you can convert "Effective Date" variable into charracter variable. Then you can compare.
Cynthia_sas
SAS Super FREQ
Hi:
In addition to converting the variable, you can also use Date constants to perform your selection or your deletion in a DATA step program (or PROC SQL step):
[pre]
if EffectiveDate = '01JAN2010'd then delete;
[/pre]

The date constant form 'DDMMMYYYY'D or 'DDMMMYY'D allows you to supply a date in "readable" format and the D at the end of the constant tells SAS to convert that value to an internal date value, so it would be as though you were specifying this:
[pre]
if EffectiveDate = 18263 then delete;
[/pre]

because '01jan2010'D is the date constant way to specify 18263 -- which represents January 1, 2010, which will be 18,263 days from Jan 1, 1960.

If EffectiveDate was a DATE/TIME variable, then you might have to use a different function to specify your comparison...something like:

[pre]
if datepart(EffectiveDate) = '01jan2010'd then delete;
[/pre]

cynthia

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

New Learning Events in April

 

Join us for two new fee-based courses: Administrative Healthcare Data and SAS via Live Web Monday-Thursday, April 24-27 from 1:00 to 4:30 PM ET each day. And Administrative Healthcare Data and SAS: Hands-On Programming Workshop via Live Web on Friday, April 28 from 9:00 AM to 5:00 PM ET.

LEARN MORE

Discussion stats
  • 3 replies
  • 2148 views
  • 0 likes
  • 4 in conversation