BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
zihdonv19
Quartz | Level 8

zihdonv19_0-1592257138733.png

 

Could someone explain the meaning of the highlighted syntax "if First.Y;"?

 

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

 

 

View solution in original post

4 REPLIES 4
ballardw
Super User

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.

 

 

Reeza
Super User

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.

 

https://go.documentation.sas.com/?docsetId=lrcon&docsetTarget=n01a08zkzy5igbn173zjz82zsi1s.htm&docse...

zihdonv19
Quartz | Level 8
thanks for your answer.
zihdonv19
Quartz | Level 8
Thanks. it is clear to me now.

Welcome to the Certification Community

 

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

 

Why Get SAS Certified.jpg

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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