- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
is the first. and last. statement temporary even though its in the data step?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
This is interesting.
32 data _null_;
33 first.sex = 30;
34 put _all_;
35 run;
first.sex=30 _ERROR_=0 _N_=1
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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