is the first. and last. statement temporary even though its in the data step?
Hi:
FIRST.byvar and LAST.byvar are automatic variables that exist for the duration of the DATA step program, but they can be used in the program. Since they are never output to the final dataset, you might consider them temporary. I prefer to think of them as automatic, like _N_ and _ERROR_, which are also available for the duration of the program but not output.
So, FIRST. and LAST. are variables, not statements. When you use FIRST. and LAST. in a program, it is typically in some kind of IF statement like this:
if last.company then output;
if first.department then dept_counter=0;
Cynthia
First and Last variables are automatic variables that are not written to the output data set.
@clqa wrote:
is the first. and last. statement temporary even though its in the data step?
This is interesting.
32 data _null_;
33 first.sex = 30;
34 put _all_;
35 run;
first.sex=30 _ERROR_=0 _N_=1
Hi:
Creating or using the variable in an assignment statement is not prohibited. But look what happens when you try to create a dataset:
There are 2 assignment statements, but only 1 variable (X) is actually written to the output data -- the FIRST.SEX variable is NOT written to the output dataset.
Cynthia
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.