Today's post was supposed to be a mail-merge example from Chapter 4 (included in the preview copy available at SAS Global Forum 2012) of SAS® Server Pages: Generating Dynamic Content.
In the book that example was not Web-based. I started with a simple example: generating a letter for a specified observation, and built on it. I had planned to something similar here but packaged for the Web - using it to illustrate some important features of PROC STREAM. My original plan was to just hard code the observation number - but I decided that was not a good idea and so I decided to:
- Allow the observation number from the SASHELP.CLASS data set for which the letter is to be generated to be passed in as a parameter.
- Have a default value used if no value is specified.
- That then led to needing to confirm that the value was an integer between 1 and the number of observations in the data set (19 in this case).
- Which then led to a simple utility macro that does that validation and assigns a default value.
(value= /* the value to be verified as an integer */
,default=1 /* default if null */
,min= /* if specified, the minimum allowed value */
,max= /* if specified, the maximum allowed value */
%let value =
%then %let value=1;
%if %length(&min) gt 0 and &value lt &min
%then %let value = &min;
%if %length(&max) gt 0 and &value gt &max
%then %let value = &max;
&value /* return the value to the input stack */
In my code, I can just add the following statement:
%let letterObs = %verifyInteger(value=&letterObs
And before ending this post, just a few comments about this macro and how I am using it:
- Note the use of the NOTDIGIT function to validate that the value contains only integers.
- I've hard-coded the value of the max parameter on the call because I know the data set only has 19 observations. I could have used the SCL data access functions to get the value if it was unknown.
- While it is true that I could define a parameter for a stored process that forces the value to be an integer, since I want these to work for the SAS/IntrNet Application Dispatcher as well, that is not an option. In addition, since I will typically want to use my generic sasServerPage and runMacro stored processes (also runnable as SAS/IntrNet Application Dispatcher programs), having the constraints on the parameter value is not really an option.
- Using the Stored Process Server: http://demos.hcsbi.com:8080/SASStoredProcess/guest?_program=/GuestDemos/sasServerPage&page=blogCalendar
- Using the SAS/IntrNet Application Dispatcher: http://demos.hcsbi.com/scripts/broker.exe?_service=ssp&_program=sspebook.sasServerPage.sas&page=blogCalendar