Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

create new variable based on next row

create new variable based on next row

create new variable based on next row

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.


RE: create new variable based on next row

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


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.

RE: create new variable based on next row

Thanks very much - so simple! I had been working on the same project all day and was thinking too much outside the box.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close