I wrote a proc sql to pull in ID, NAME, LS_DATE1 through 4
proc sql;
create table Test as
select ID,NAME,LS_DATE1,LS_DATE2.........etc
from my_table;
quit;
Some rows will have the LS_DATES populated (Not All). Each row will usually only have one date in one of the LS_DATE columns. If there are multiple dates in multiple columns in the same row, I want the last date that appears. I want to get the date and place it in its own GET_DATE column with the same value. I will use the GET_DATE in calulating the difference in days later.
So I need two examples, one that assumes only one date per column per row and another that looks for the last date in a row if there are multiples.
SAMPLE
ID NAME LS_DATE1 LS_DATE2 LS_DATE3 LS_DATE4
1 Smith 4/15/12
2 Bryant 1/12/13
3 Jones 5/1/13
4 Thomas 12/13/06
If those dates are numeric, use coalesce(), otherwise use coalescec():
proc sql;
create table Test as
select ID,NAME,coalesce(LS_DATE4,LS_DATE3, LS_DATE2,LS_DATE1) as GET_DATE /*put the last date first*/
from my_table;
quit;
HTH,
Haikuo
data Test
set Test1;
Get_Date=coalesce(LS_DATE1
LS_DATE2 LS_DATE3 Ltr_Dt 😞
run
How can I do the same thing except in a dataset. All these variables are dates
If you need a fast pass for solving your imminent issues, you already have one. If you want to learn how it works inside-out, now it is good for you to spend sometime reading the manual:
This is a new function for me Coalasce for numeric and coalescec for string. Read articles realted to it on google and to be frank this is a very helpful function for me......Thanks guys
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.