BookmarkSubscribeRSS Feed
GMP1978
Calcite | Level 5

I want to create a new variable and return a 1 when Date1 is greater than Date2 and have it formatted as a numeric.

 

PROC SQL;

CREATE TABLE Direct AS

SELECT RECEIPTS.*

,Case When DATE1 GT Date2 then '1' ELSE '0' end as Date_Compare format=comma8.2

FROM RECEIPTS

QUIT;

1 REPLY 1
ballardw
Super User

@GMP1978 wrote:

I want to create a new variable and return a 1 when Date1 is greater than Date2 and have it formatted as a numeric.

 

 


First, don't put quotes around a value you want as numeric. Quotes define character values.

You can also try

 

(date1 gt Date2) as Date_compare

SAS will return 1 for true and 0 for false for simple logical comparisons though you may need to think about what you want if either of the two variables is missing

 

And why do you want comma8.2 format for a value range of 0 and 1???

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 1 reply
  • 693 views
  • 2 likes
  • 2 in conversation