- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I have the following code. I've created two new variables ReceivedDate and StartDate and if these do not match, I'd like the value of 'PREBOOKED" to be returned. below is my code and 'PREBOOKED" is being returned in every instance, as it appears as though it's reading the above variables as Datetime.
The data source is from an excel spreadsheet.
I've searched this forum and I'm using datepart in my coded, but it appears I'm using it incorrectly.
data WORK.IIS_Testa;
set WORK.IIS_Test ;
ReceivedDate=datepart(Received);
format ReceivedDate ddmmyyp10.;
StartDate=datepart('Required Start'n);
format StartDate ddmmyyp10.;
run ;
data WORK.IIS_Testb;
set WORK.IIS_Testa;
if ReceivedDate <> StartDate then Services ='PREBOOKED';
run;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Maxim 2: Read the Log:
96 data WORK.IIS_Testb; 97 set WORK.IIS_Testa; 98 if ReceivedDate <> StartDate then Services ='PREBOOKED'; NOTE: The "<>" operator is interpreted as "MAX". 99 100 run;
That's why I prefer to use the "ne" mnemonic for a check for unequal.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Received Required Start
03MAR20:10:36:02 03MAR20:10:40:00
ReceivedDate StartDate
03.03.2020 03.03.2020
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Your code is correct.
You say that " 'PREBOOKED" is being returned in every instance" but
your output displays only
ReceivedDate StartDate
03.03.2020 03.03.2020
you did not display the services value.
Please post the output of:
proc print data=IIS_Testb; run;
to show us the issue you claimed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Why are you using the MAX operator in your IF statement? That will test if largest date not zero or missing.
Perhaps you intended to test if they were not equal instead?
if ReceivedDate ne StartDate then Services ='PREBOOKED';
if not (ReceivedDate = StartDate) then Services ='PREBOOKED';
if ReceivedDate ^= StartDate then Services ='PREBOOKED';
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Maxim 2: Read the Log:
96 data WORK.IIS_Testb; 97 set WORK.IIS_Testa; 98 if ReceivedDate <> StartDate then Services ='PREBOOKED'; NOTE: The "<>" operator is interpreted as "MAX". 99 100 run;
That's why I prefer to use the "ne" mnemonic for a check for unequal.