DATA Step, Macro, Functions and more

datetime function MDY problem

Reply
New Contributor
Posts: 3

datetime function MDY problem

This seems like a simple problem, but it's making me crazy.

So I'm trying to say that if a date variable (disc_date) is equal to one of a certain set of dates, it should be set to missing.

Here is the code i'm using:

if disc_date in (MDY(10,13,2003),MDY(11,11,2003),MDY(11,27,2003),MDY(11,28,2003),MDY(1,19,2004),MDY(2,12,2004),MDY(2,16,2004),MDY(3,1,2004),MDY(5,31,2004)) then disc_date = .D;

I get the error:
ERROR 22-322: Syntax error, expecting one of the following: a quoted string, a numeric constant, a datetime constant, a missing value, iterator, (.

indicating the first "MDY" function.
Why doesn't it like this??

Anyone have any ideas?
N/A
Posts: 0

Re: datetime function MDY problem

try using this

if disc_date in ( '13oct2003'd ) then disc_date = .;

GL
Super User
Posts: 19,791

Re: datetime function MDY problem

I thought the in (a b c d) didn't use comma's.

Ie

(MDY(10,13,2003) MDY(11,11,2003) MDY(11,27,2003)) might work.
SAS Super FREQ
Posts: 8,865

Re: datetime function MDY problem

Hi:
I always use a comma. Although I believe in some circumstances, the IN operator will be forgiving.

When in doubt, it's always a good idea to check the documentation.
http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#/documentation/cdl/e...

cynthia
SAS Employee
Posts: 73

Re: datetime function MDY problem

Posted in reply to Cynthia_sas
hi all,

that error is not because of comma or space delimiter.
its becas of using sas function inside the IN operator.
We should have to use numeric or character constants as arguments for IN operator (not sas functions....)

It doesn't matter whether u r using comma or space as delimiter. both r acceptable.

Pavan. Message was edited by: Pavan@SAS
SAS Super FREQ
Posts: 8,865

Re: datetime function MDY problem

Posted in reply to Pavan_SAS
You are correct that the original error was the use of the MDY function with the IN operator, when the date constant or a SAS date value would have been the preferred approach.

However, my comment was ONLY addressing the use of commas or not. IN will allow spaces, but the documentation shows the use of commas.

cynthia
Ask a Question
Discussion stats
  • 5 replies
  • 237 views
  • 0 likes
  • 5 in conversation