BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Haydn
Quartz | Level 8

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;
1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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.

View solution in original post

5 REPLIES 5
sustagens
Pyrite | Level 9
Can you post sample data please.
Haydn
Quartz | Level 8
This what is being returned

Received Required Start
03MAR20:10:36:02 03MAR20:10:40:00


ReceivedDate StartDate
03.03.2020 03.03.2020
Shmuel
Garnet | Level 18

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. 

Tom
Super User Tom
Super User

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';
Kurt_Bremser
Super User

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.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1515 views
  • 2 likes
  • 5 in conversation