Could someone explain the meaning of the highlighted syntax "if First.Y;"?
Thanks.
First. and the companion Last. work with variables on a BY statement in a data step to indicate if the current record holds a value that is "first" or "last" for that level of the By variable. These are Boolean values, with 1= True and False=0.
The data as always with a BY statement needs to be sorted by the variables on the by statement and in that order unless the "notsorted" option is used.
An IF statement without an assignment or "do" block of code is a subsetting if, which means only the records where the value is true are kept for the output to the data set.
Create the data Work.one with a data step to get the values as shown, SORT the data by X and Y then run the shown code. Since you provided a PICTURE and it isn't possible to create data or code files from pictures, at least easily, I 'll leave that to you.
First. and the companion Last. work with variables on a BY statement in a data step to indicate if the current record holds a value that is "first" or "last" for that level of the By variable. These are Boolean values, with 1= True and False=0.
The data as always with a BY statement needs to be sorted by the variables on the by statement and in that order unless the "notsorted" option is used.
An IF statement without an assignment or "do" block of code is a subsetting if, which means only the records where the value is true are kept for the output to the data set.
Create the data Work.one with a data step to get the values as shown, SORT the data by X and Y then run the shown code. Since you provided a PICTURE and it isn't possible to create data or code files from pictures, at least easily, I 'll leave that to you.
I find this page particularly helpful in explaining first. and last. logic, specifically the examples where they illustrate the values for each line of data.
This is a knowledge-sharing community for SAS Certified Professionals and anyone who wants to learn more about becoming SAS Certified. Ask questions and get answers fast. Share with others who are interested in certification and who are studying for certifications.To get the most from your community experience, use these getting-started resources:
Community Do's and Don'ts
How to add SAS syntax to your post
How to get fast, helpful answers
Ready to level-up your skills? Choose your own adventure.