I have a column for each employee start date (startdt1 thru startdt12) in a new position, and a column for their last promotion date. How can I create a loop that will tell me when the promotion date is between startdt(i) and startdt(i+1) and output to a new variable with "Start_DT(i)" ? Thanks.
data have; input (Promodt Startdt1 Startdt2 Startdt3 Startdt4 Startdt5 Startdt6 Startdt7 Startdt8 Startdt9) (:date9.); format _all_ date9.; cards; 22-Jun-08 29-Sep-97 15-Mar-98 21-Apr-02 10-Dec-06 23-Dec-07 22-Jun-08 20-Jun-10 27-Jan-13 . 8-Nov-09 18-Oct-04 3-Apr-05 8-Nov-09 . . . . . . 23-Mar-03 22-Mar-99 25-Jan-04 3-Oct-04 1-Mar-09 2-Jan-11 . . . . ; run; data have; set have; array s{*} start:; do i=dim(s) to 1 by -1; if Promodt ge s{i} and not missing(s{i}) then do; new_var=vname(s{i}); leave; end; end; drop i; run;
Ksharp
I think you need to clarify your question, and preferably post some sample data, both of what your data currently looks like and what you want the output to be.
Thanks for the response Reeza. As you can see in the sample data attached, I have a column for an employee's last promotion date and nine columns that reflect position start dates for that employee. I want to quickly scan the start dates and find the start date of the position the employee was promoted in. Once that start date is determined I want to create a new variable "Promoted In" that lists the variable name as the data -- that is Startdt1-9.
data have; input (Promodt Startdt1 Startdt2 Startdt3 Startdt4 Startdt5 Startdt6 Startdt7 Startdt8 Startdt9) (:date9.); format _all_ date9.; cards; 22-Jun-08 29-Sep-97 15-Mar-98 21-Apr-02 10-Dec-06 23-Dec-07 22-Jun-08 20-Jun-10 27-Jan-13 . 8-Nov-09 18-Oct-04 3-Apr-05 8-Nov-09 . . . . . . 23-Mar-03 22-Mar-99 25-Jan-04 3-Oct-04 1-Mar-09 2-Jan-11 . . . . ; run; data have; set have; array s{*} start:; do i=dim(s) to 1 by -1; if Promodt ge s{i} and not missing(s{i}) then do; new_var=vname(s{i}); leave; end; end; drop i; run;
Ksharp
Thanks KSharp - works perfectly.
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.
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.