DATA Step, Macro, Functions and more

Indicate the first record in a data set

Accepted Solution Solved
Reply
Regular Contributor
Posts: 216
Accepted Solution

Indicate the first record in a data set

Hi

In processing a data step, is there a way to indicate the first record in an overall data set? I know using 'first' works to indicate the first grouping of a certain combination of variables, but I am wondering about the entire data set.

Paul


Accepted Solutions
Solution
‎03-25-2014 12:18 PM
Trusted Advisor
Posts: 1,615

Re: Indicate the first record in a data set

The predefined variable _n_ will have the value 1 for the first record in a data set

View solution in original post


All Replies
Solution
‎03-25-2014 12:18 PM
Trusted Advisor
Posts: 1,615

Re: Indicate the first record in a data set

The predefined variable _n_ will have the value 1 for the first record in a data set

Regular Contributor
Posts: 216

Re: Indicate the first record in a data set

Thanks Paige.

Paul

Respected Advisor
Posts: 4,651

Re: Indicate the first record in a data set

If your datastep involves reading a single dataset then testing _N_=1 will signal the first datastep iteration. Otherwise, using the INDSNAME=myVariable option in the SET statement will give you a dataset name to compare with the previous iteration (IF myVariable ne lag(myVariable)) to detect the fiirst observation from each new dataset, including the first one.

PG

PG
Regular Contributor
Posts: 216

Re: Indicate the first record in a data set

Thanks PG. I have one data set, but that is good to know for the future.

Paul

☑ This topic is SOLVED.

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

Discussion stats
  • 4 replies
  • 196 views
  • 0 likes
  • 3 in conversation