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

I have a table of records with a Start Date and an Entered Date (SOENTD). I have the below case statement to populate a field based on the the START_DT values or lacktherof. Problem is that the Nul Start Dates are not being registered and are defaulting to 'Existing' when they should be 'N/A'

Do I need to use Coalesce in this to do what I need it to? Any help is appreciated. Thank You!

 

proc sql;

update TBL_EX

set DATA_IND = case when START_DT >= SOENTD then 'New'

                                    when START_DT < SOENTD then 'Existing'

                                     when START_DT is null then 'N/A'

                             end;

quit;

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
case when START_DT >= SOENTD then 'New'
when START_DT < SOENTD and not missing(start_dt) then 'Existing'
when START_DT is null then 'N/A'
end

Missing values are considered to be less than non-missing values, that's why your original code doesn't work. It has nothing to do with the fact that the variables contain date values.

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26
case when START_DT >= SOENTD then 'New'
when START_DT < SOENTD and not missing(start_dt) then 'Existing'
when START_DT is null then 'N/A'
end

Missing values are considered to be less than non-missing values, that's why your original code doesn't work. It has nothing to do with the fact that the variables contain date values.

--
Paige Miller
Reeza
Super User
Move your NULL condition to the start since SAS considers missing values as the lowest numeric value.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1389 views
  • 1 like
  • 3 in conversation