Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9130169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:54:39+00:00 2026-06-17T07:54:39+00:00

In this data step I do not understand what if last.y do… Could you

  • 0

In this data step I do not understand what if last.y do…
Could you tell me ?

data stop2;
    set stop2;
    by x y z t;

if last.y; /*WHAT DOES THIS DO ??*/

    if t ne 999999 then
        t=t+1;
    else do;
            t=0;
        z=z+1;
    end;
run;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T07:54:41+00:00Added an answer on June 17, 2026 at 7:54 am

    LAST.Y refers to the row immediately before a change in the value of Y. So, in the following dataset:

    data have;
    input x y z;
    datalines
    1 1 1
    1 1 2
    1 1 3
    1 2 1
    1 2 2
    1 2 3
    1 3 1
    1 3 2
    1 3 3
    2 3 1
    2 3 2
    2 3 3
    ;;;;
    run;
    

    LAST.Y would occur on the third, sixth, ninth, and twelfth rows in that dataset (on each row where Z=3). The first two times are when Y is about to change from 1 to 2, and when it is about to change from 2 to 3. The third time is when X is about to change – LAST.Y triggers when Y is about to change or when any variable before it in the BY list changes. Finally, the last row in the dataset is always LAST.(whatever).

    In the specific dataset above, the subsetting if means you only take the last row for each group of Ys. In this code:

    data want;
    set have;
    by x y z;
    if last.y;
    run;
    

    You would end up with the following dataset:

    data want;
    input x y z;
    datalines;
    1 1 3
    1 2 3
    1 3 3
    2 3 3
    ;;;;
    run;
    

    at the end.

    One thing you can do if you want to see how FIRST and LAST operate is to use PUT _ALL_;. For example:

    data want;
    set have;
    by x y z;
    put _all_;
    if last.y;
    run;
    

    It will show you all of the variables, including FIRST.(whatever) and LAST.(whatever) on the dataset. (FIRST.Y and LAST.Y are actually variables.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This data is for a holiday cottage's simple accommodation calendars. The data is simple
I have this data in cell A1: Majestic Properties Design District, LLC, Ste. 101,
If user insert this data 16 HOUSEHOLD STAND FAN AA070021A the output should be
I need to make this data variable global: $.ajax({ url: get_data.php, cache: false, dataType:
i Want to fetch this data using json decode. Please Help.. So far i
i have this data | car_name | year | price | Honda | 2011
I am accessing this data from a web server using NSURL, what I am
I have this data from a xml file: <?xml version=1.0 encoding=utf-8 ?> <words> <id>...</id>
I have this data: /blabla/blabla (abs,def) /yxz I use this regex (.*)(?:\(([^$]*)\))?\n But it
I have this data: 1, 0., 0., 1500. . . 21, 0., 2000., 1500.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.