- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi everyone! I'm working my way through the SAS Programming 2: Data Manipulation Techniques course. I noticed in the Loops part of the course that some of the expressions in the Do loop require an equal sign and some don't. For example, in Practice p206p04.sas the code reads:
data IncreaseDayVisits;
set pg2.np_summary;
where Reg='NE' and DayVisits<100000;
IncrDayVisits=DayVisits;
Year=0;
do while (IncrDayVisits<100000);
IncrDayVisits=IncrDayVisits*1.06;
Year+1;
end;
format IncrDayVisits comma12.;
keep ParkName DayVisits IncrDayVisits Year;
run;
The lines in the above code in blue are both formula expressions, however the first formula requires an assignment of IncrDayVisits= and the second formula doesn't require an assignment with an equal sign.
Can anyone clarify what the difference is? Why does one need an assignment statement with an equal sign and the other does not?
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
This is an assignment statement:
IncrDayVisits=IncrDayVisits*1.06;
The expression to the right of = is resolved, and the result is assigned to the variable IncrDayVisits. The value of IncrDayVisits will be reinitialized to missing for each iteration of the data step, and if IncrDayVisits is missing when the expression is evaluated, the result of the expression will also be missing.
This is a SUM statement:
Year+1;
The variable to the left of + is an accumulator variable. Accumulator variable values are not automatically reinitialized when the DATA step iterates - the values are instead retained across iterations. After the expression to the right of + is evaluated, and the result is summed to the existing value of the accumulator variable (the equivalent of Year=SUM(Year,1), in this case). Summing will ignore missing values, so if Year is missing, the resulting value of Year is 1.