Hi:
CALL SYMPUTX is used to insert Macro variables into a macro variable symbol table because the values stored in the macro variables can be based on information from reading the SAS dataset -- as in this case where we want to know the starting and stopping obs number for the last 10 observations in the input data. In the first example, I create the CURRENTOBS variable by capturing the _N_ value and then for PROC PRINT, I hard-coded the firstobs= and obs= values in the program. (keep in mind that if the data are sorted differently, not in alpha order, then the CURRENTOBS value for each row would be for a different name.)
In the second program, I also create CURRENTOBS in the DATA step program. Then, using the END= option allows me to use conditional logic when SAS is handling the last observation in the input data set. In this case, on the last row, I now know the number of obs in the data file and I just need to subtract to get the value for FIRSTOBS. My helper variables are created using CALL SYMPUTX and since I stored the helper macro variables in the Global Symbol Table, they are available throughout this SAS session, until I delete them from the Global Symbol Table or the session ends. That way, they are available to use in the PROC PRINT step.
Knowing about and using helper macro variables like this is a useful technique for taking the information from one program and saving it into a macro variable for use in a subsequent step. Of course, SAS Macro processing and the Macro facility can be very, very much more complicated than what I show here, but the amount of code that is used is minimal and if you use the var statement to control the order of the variables for PROC PRINT, you don't have to fiddle with the LENGTH statement to make sure that CURRENTOBS appears first. The VAR statement, to me is a better way to control variable order for report purposes. Fiddling with the order of the variables in internal storage is not really necessary, if the end result is a report. (in my opinion I would rather control the order of variables with a VAR or COLUMN statement instead of relying on the data to be in a certain order when internally stored.)
Cynthia
... View more