Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

create new variable based on next row

Status
Not open for further replies.

dodger7

Programmer
Apr 4, 2011
2
0
0
GB
Hi guys

I have a dataset which has the variable 'job_ID'. This variable starts from 1 and increments down each row and will end around number 50 (will change each time). This 'Job_ID' represents each job in a batch of jobs.

I want to create a new variable called 'batch_ID'. This should start from 1, then continue to be number 1 all the way down the 'Job_ID' variable until it gets to the number 1 again - then the batch_id should increment to 2 and so on.

An example of what I want the 'batch_id' to look like is this:

job_id job_name batch_id
1 1.0 1
2 1.1 1
3 1.2 1
4 1.3 1
1 1.0 2
2 1.1 2
3 1.2 2
1 1.0 3
2 1.1 3

and so on.
Any help much appreciated.

Cheers
jamie
 
You can retain the >new< variable batch_id and increment it according to the specified condition, e.g.

Code:
retain batch_id 0;
if job_id eq 1 then 
  batch_id = batch_id+1;

Plug it into your datastep and you should have the batch_id set properly.
 
Thanks very much - so simple! I had been working on the same project all day and was thinking too much outside the box.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top