Write and run SAS programs in your web browser

Regarding first.(variable) and last.(variable)

Accepted Solution Solved
Reply
Contributor
Posts: 42
Accepted Solution

Regarding first.(variable) and last.(variable)

Hi,
Can someone explain what does this mean?

FIRST_REGNUMBER=FIRST.REGNUMBER ;
LAST_REGNUMBER=LAST.REGNUMBER;

I had tried to read the explanation from different source but I am still confuse.

Thank you.


Accepted Solutions
Solution
‎02-11-2018 08:49 PM
Super User
Super User
Posts: 9,397

Re: Regarding first.(variable) and last.(variable)

A temporary flag is added to the data, called first.<variable> and last.<variable> for each variable in the by group, this flag can then be used to determine if the record is the first or last occurence within the by group.

There are many guidance documents out there about this:

https://onlinecourses.science.psu.edu/stat481/node/9

For example.

 

Also, as a tip, do not code all in uppercase.

 

View solution in original post


All Replies
Frequent Contributor
Posts: 85

Re: Regarding first.(variable) and last.(variable)

It gives you the first/last row of a group. A quick example:

data aa1;
    set sashelp.cars;
    by make;

    if first.make then
        output;
    else if last.make then
        output;
run;

Gives you a table with only the first and last row per make in the table

Solution
‎02-11-2018 08:49 PM
Super User
Super User
Posts: 9,397

Re: Regarding first.(variable) and last.(variable)

A temporary flag is added to the data, called first.<variable> and last.<variable> for each variable in the by group, this flag can then be used to determine if the record is the first or last occurence within the by group.

There are many guidance documents out there about this:

https://onlinecourses.science.psu.edu/stat481/node/9

For example.

 

Also, as a tip, do not code all in uppercase.

 

Highlighted
Super User
Posts: 9,868

Re: Regarding first.(variable) and last.(variable)

Since the automatic first. and last. variables (which are created when a by statement is present in the data step) are not included in any output data, these assignments are a technique to make the values visible in the output dataset.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 130 views
  • 3 likes
  • 4 in conversation