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;
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.
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.
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';
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.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.