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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
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

View solution in original post

4 REPLIES 4
Reeza
Super User

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.

Mavereck95
Calcite | Level 5

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.

Ksharp
Super User
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

Mavereck95
Calcite | Level 5

Thanks KSharp - works perfectly.

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
  • 4 replies
  • 1004 views
  • 0 likes
  • 3 in conversation