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;
@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???
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.