Example: quiz answers

113-2007: List Processing Basics: Creating and …

Paper 113-2007 List Processing basics : Creating and using lists of Macro VariablesRonald J. Fehd, Centers for Disease Control and Prevention, Atlanta, GA, USAArt Carpenter, CA Occidental Consultants, Vista, CA, USAABSTRACTList Processing or dynamic programmingtechniques free up your programmingtime by eliminating hard coded parame-ter values. List values can be obtained di-rectly from information you already have,and there is more than one way to do it!Commonly the list is stored as series ofmacro variables or as a macro variablewith a series of values or even as valuesin a data paper compares and contrasts thebasic methods of treating variable val-ues as parameters and placing them intorepetitive :intermediate :call execute, call symput, dynamic pro-gramming, into:, list Processing , self-modifyingContentsPreparing a Routine2 Making Lists3 using Lists4 Make and Iterate a Macro Array.

Jun 06, 2008 · Paper 113-2007 List Processing Basics: Creating and Using Lists of Macro Variables Ronald J. Fehd, Centers for Disease …

Tags:

  Basics, Using, Lists, Creating, Processing, List processing basics, Creating and, Creating and using

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Advertisement

Transcription of 113-2007: List Processing Basics: Creating and …

1 Paper 113-2007 List Processing basics : Creating and using lists of Macro VariablesRonald J. Fehd, Centers for Disease Control and Prevention, Atlanta, GA, USAArt Carpenter, CA Occidental Consultants, Vista, CA, USAABSTRACTList Processing or dynamic programmingtechniques free up your programmingtime by eliminating hard coded parame-ter values. List values can be obtained di-rectly from information you already have,and there is more than one way to do it!Commonly the list is stored as series ofmacro variables or as a macro variablewith a series of values or even as valuesin a data paper compares and contrasts thebasic methods of treating variable val-ues as parameters and placing them intorepetitive :intermediate :call execute, call symput, dynamic pro-gramming, into:, list Processing , self-modifyingContentsPreparing a Routine2 Making Lists3 using Lists4 Make and Iterate a Macro Array.

2 5 Make and Scan a Macro Variable .. 6 Write Calls to a Macro Variable .. 8 Write to File then Include .. 9 Call Execute .. 10 Summary13 Suggested Reading .. 13 Bibliography .. 13 Appendix15 Project Files for Batch Processing .. 15 Example Files for Workshop .. 16 Solutions to Examples .. 20 INTRODUCTIONOne of the greatest strengths of the SASR macro language is its ability to build and execute repetitive code. Thelevel of repetition that encourages conversion to a macro depends on the tolerance of the programmer. For Ronand Art a program with a repetition of more than two items is a candidate for we write more sophisticated macros we want to have the macrodetermine as much of the information that it needs as possible.

3 In asimple case consider the macro%doloop:%macro DoLoop;%do I = 1 %to 5;%*..;This loop has a hard coded number of repetitions (5). We can gener-alize by passing the number of repetitions as a parameter:%macro DoLoop(Count);%do I = 1 %to %*..;In a dynamic coding solution the macro will include code so that thenumber of repetitions can be determined by the macro DoLoop;%*.. code determines Count;%do I = 1 %to %*..;The final solution is one kind of dynamic process, and in the following sections of this paper we will present severaldifferent approaches and techniques that are commonly used to solve dynamic coding a dynamic programming situation it is very often desirable to process one or more operations for a series of items themselves may be data sets, variables in a data set, (columns in a table), or values of a column within hallmark of dynamic programming techniques is that the program itself will determine what the list is, build it,1 SASG lobalForum2007 Hands-on Workshops and then use it.

4 In a dynamic program all this is done without programmer the following simpleProcReportstep which routes the output html file = "& "2style = journal;34 Title "Sales in Africa";56 PROC Report data = ;8where region = Africa ;9column product subsidiary, sales;10define product / group;11define subsidiary / across;12define sales / analysis ;13run;14ods html close;If we want a similar report for each region we cannot simply use abystatement in the PROC step because we wanttheTitleand thehtmlfilename to contain the name of the region. Hard coding the value of one region whiletesting is no problem, for two it is irritating, for three it is time to find a better solution.

5 We need a dynamic solutionthat can determine the number of regions, the values of each, and then execute this step for each the following sections we examine this problem from several anglesand we show several different techniques that can be used to build theability to provide the needed examples show the concepts of testing the routine as it is beingdeveloped. prepare routine identify program parameter(s) convert program to routine make list of parameter values iterate with each value: call routinePREPARING A ROUTINEIDENTIFY PROGRAM PARAMETERSOur report has three occurences of the stringAfrica. This is the firstvalue of the variable Region in the data set file = 2 Title Sales inAfrica ;3where Region = Africa ;CONVERT TO ROUTINEThe first step in converting our program to a routine is to keep theprogram running by making it into a parameterized include file.

6 Addone macro variable for each parameter and replace the occurences ofeach parameter value with the macro and replace the three occurences of the stringAfricawith themacro variable reference& Note that the prefix to the macrovariable reference is the special character ampersand (&) and the suf-fix is the character dot (.). In the filename-extension the first dot endsthe macro variable reference and the second dot separates the file-name and the ; file = "& "3 Title "Sales in 4where Region = " 2 SASG lobalForum2007 Hands-on Workshops CONVERT TO MACROF inally change the allocation of the macro variablefrom%Letto% Report(Region=Africa).

7 File = "& "3 Title "Sales in 4where Region = " The next task is to identify the list of pa-rameter values and decide how best togenerate the macro calls shown here inthe test section at the bottom of the lines 5 9: Since one value con-tains a slash (/) we create a newvariableFilenameand change theslash to a hyphen to avoid an oper-ating system clash of folderCentralAmerica/Caribbeannot : How to generate these macro calls? (Region = Africa);29%Report(Region = Asia );30%Report(Region31= Central America/Caribbean);See Report(InData = ,Region =3,OutPath = /*here: same folder*/4);5%local Filename; %Let Filename = 6%** change slash to hypen in7 Central America/Caribbean;8%If %index(&Region,/) %then %Let Filename =9%sysfunc(translate(&Region.))

8 ,-,/));1011ods html file = "& "12style = journal;1314 Title "Sales in 1516 PROC Report data = & ;18where Region = " 19column Product Subsidiary, Sales;20define Product / group;21define Subsidiary / across;22define Sales / analysis ;23run;24ods html close;25run; %mend Report;To speed up our testing, we write a verysimple test macro which only lists its pa-rameter ReportTest(Region = );2%put _local_;3run; %Mend;MAKING LISTSWHAT IS A LIST?In conversation we use the wordlistto mean any collection ofitems,however they may be related. An example would be a todo or shop-ping list. The items in the list share a common property: tasks to bedone, items to purchase.

9 In a formal language, such as set theory,a list is defined as an unordered set. In the SAS language a list isa table. For our discussion here, the list is a collection of the uniquevalues of the variable region of the table of List1. natural language: list contains items2. formal language: an unordered set3. SAS: data set or tableWHERE ARE lists ?SAS provides many unique data sets in either sashelp views or sqldictionary tables. DiIorio and Abolafia [5, ] provide a com-parision of sashelp views and sql dictionary tables and a dozen exam-ples. Most summarization procedures freq and means/summary can produce an output data set which contains a unique list of vari-able values.

10 Fehd [8, ] provides usage examples ofthe more common sql dictionary of Lists1. sashelp views2. sql dictionary tables3. summarization procedure output3 SASG lobalForum2007 Hands-on Workshops MAKING UNIQUE FROM DATAFor this reporting example con-sider these methods to extract aunique list of parameter valuesfrom a data set. Each method pro-duces a data set,Regions, with alist of unique values of the variableRegion. We use this list to writethe calls to the Ex00: review orEx02: symputx. proc Sort data = (keep = Region)3out = Regions4nodupkey;5by Region; proc SQL; create table Regions as2select distinct Region3from ;4quit; using LISTSH aving obtained a list of unique values ina table, we next need to convert the liststored in the table to a list available in themacro environment.


Related search queries