DATA Step, Macro, Functions and more

Using or operator in if and then statement

Reply
Super Contributor
Posts: 272

Using or operator in if and then statement

Dear,

 

In my data vdate variable contains the following values.  I used the following code to convert to isodate. But it gives me " Invalid argument to function INPUT function".

Pleas help why.]

I think my code looks ok.

 

 

id              vdate(character)

1               17/Jul/2015                

2

3                UN/Jan/2016

 

 

code; 

 

if vdate  ^= ''  or compress(vdate,'/') ^= : 'UN' then date1=put(input(vdate,date11.),is8601da.);

 

;

           

 

Super User
Posts: 17,829

Re: Using or operator in if and then statement

The log should tell you the offending record which should help you narrow down the issue in your logic. 

 

Also, verify if you want OR or AND

Trusted Advisor
Posts: 1,378

Re: Using or operator in if and then statement

[ Edited ]

What you realy meant by: 

        if vdate  ^= ''  or compress(vdate,'/') ^= : 'UN' then date1=put(input(vdate,date11.),is8601da.);

 

is   if   NOT (vdate = ' '  or compress(vdate,'/') = : 'UN' )  then date1=put(input(vdate,date11.),is8601da.);

 

which, after opening the brackets convert into:

     if vdate  ^= ' '  AND  compress(vdate,'/') ^= : 'UN' then date1=put(input(vdate,date11.),is8601da.);

 

Other solution is:    date1=put(input(vdate,?? date11.),is8601da.);

which in case of vdate is not valid then date1 is missing value.

 

 

 

 

Super User
Posts: 5,082

Re: Using or operator in if and then statement

While I agree with the earlier comments, it might be easiest to understand the observations you are processing if you switched to:

 

if not (vdate in : (' ', 'UN')) then .....;

 

The way you have written the logic, every single observation meets the IF conditions.

Ask a Question
Discussion stats
  • 3 replies
  • 294 views
  • 3 likes
  • 4 in conversation