BookmarkSubscribeRSS Feed
alaxman
Obsidian | Level 7

I have this piece of code:

 

if filldates(i)<= start_dt + ii -1 <= filldates(i)+days_supply(i)-1
		then daydummy(ii)=1;
		end;

Can someone help me understand what the IF statement is checking? There doesn't seem to be an AND or an OR operator, but two conditional operators (<=). 

5 REPLIES 5
SASKiwi
PROC Star

As I understand it, the IF condition is true if (start_dt + ii -1) is between the values of (filldates(i)) and (filldates(i)+days_supply(i)-1).

 

The lack of brackets in this expression is concerning and would make it easier to read:

if filldates(i) <= (start_dt + ii -1) <= (filldates(i)+days_supply(i)-1)
		then daydummy(ii)=1;
		end;

 

 

alaxman
Obsidian | Level 7
Thank you!
Tom
Super User Tom
Super User

A < B < C is shorthand for A<B AND B<C.

I assume that filldates and days_supply are array names and i is the index into the array.  Although they could be user defined functions.

 

Stick your condition into a WHERE statement and SAS will show you how it is interpreted in the LOG.

908   data _null_;
909     set sashelp.class;
910     where AGE <= HEIGHT <= WEIGHT ;
911   run;

NOTE: There were 18 observations read from the data set SASHELP.CLASS.
      WHERE (AGE<=HEIGHT) and (HEIGHT<=WEIGHT);
alaxman
Obsidian | Level 7
Thank you!
tarheel13
Rhodochrosite | Level 12

It means start_dt + ii -1 is >= filldates(i) AND start_dt + ii - 1 is <= filldates(i) + days_supply(i)-1.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1393 views
  • 3 likes
  • 4 in conversation