Question-161: What is the FIRST.variable and LAST.variable?

Answer: These are variables that SAS creates for each BY variable. SAS sets FIRST.variable when it is processing the first observation in a BY group, and sets LAST.variable when it is processing the last observation in a BY group. These assignments enable you to take different actions, based on whether processing is starting for a new BY group or ending for a BY group.

Question-162: In which scenario you don’t have to preprocess the data if you are going to use the By-group processing?

Answer: Data does not require pre-processing if the observations in all of the data sets occur in one of the following patterns.

 

  • ascending or descending numeric order
  • ascending or descending character order
  • not alphabetical or numerical order, but grouped in some way, such as by calendar month

 

If the observations are not in the order that you want, sort the data set before using BY-group processing.

 

Question-163: Can you explain the BY statement, in the SET statement?

Answer: When you use the BY statement in the SET statement of the DATA it would do the following things

  • The data sets listed in the SET statement must be indexed or sorted by the values of the BY variable or variables.
  • The DATA step automatically creates two variables, FIRST. and LAST., for each variable in the BY statement.
  • and LAST. identify the first and last observation in each BY group, respectively.

 

Question-164: What is the use of BY group statements?

Answer: If you use the BY Group statement then it would create a group for the variable specified in the BY group statement and keep all the data with same value in the same group.