List Processing Development
From sasCommunity
Templates and Tools for Testing
Contents |
What You Need
- folder for list processing: C:\SAS-site\includes
- autoexec.sas
- CallXinc.sas Call_Execute_Parameterized_Include
- List making utilities Making_Lists
- List of Dictionaries
- Naming Conventions
* name: autoexec.sas;
*filename SiteIncl ('.'
<directory-specification: list processing library>);
filename SiteIncl ('.' 'C:\SAS-site\includes');
Concept Review
HIPO
Hierarchical
- Input: data set, or file
- Process: encapsulated in routine, or subroutine
- Output: from Process, to data set, or file
see
- Hierarchy and Input-Process-Output Charts http://www.scribd.com/doc/5339259/HIPO-LECTURE
- HIPO (Hierarchy plus input-process-output)
http://www.hit.ac.il/staff/leonidM/information-systems/ch64.html
- HIPO and Integrated Program Design http://www.research.ibm.com/journal/sj/152/ibmsj1502D.pdf
- HIPO Diagrams http://yourdon.com/strucanalysis/wiki/index.php?title=Chapter_15#HIPO_DIAGRAMS
Lists
- array contains elements
- list contains items;
In this article lists are assumed to be unordered, but, in fact, are in alphabetical order, due to their being produced by various procedures.
Program Types
- module: calls routines and subroutines
- routine: calls subroutines
- subroutine: no calls
Parameterized Include Programs
Given an ad hoc program:
PROC Print data = SAShelp.Class
(where = (Sex eq 'F'));
title2 'SAShelp.Class.Sex eq F';
run;
... and comparing it to a later request:
PROC Print data = SAShelp.Class
(where = (Sex eq 'M'));
title2 'SAShelp.Class.Sex eq M';
run;
we can prepare a Parameterized Include Subroutine:
* name: print-data-where;
PROC Print data = &Data
(where = (&Where.));
title2 "&Data.&Where.))";
run;
and a hard-coded demonstration of a Parameterized Include Routine or Module, which calls the subroutine:
%Let Data = SAShelp.Class; %Let Where = Sex eq 'F'; %Include Project(print-data-where); %Let Where = Sex eq 'M'; %Include Project(print-data-where);
Sources of Lists
- Proc Contents, recommended
- SAShelp views, deprecated
- SQL dictionary tables
Beginning in v9, SAShelp views are pointers to SQL dictionary tables.
PROC SQL; describe view SAShelp.vColumn;
describe view SAShelp.vTable;
quit;
The log shows:
NOTE: SQL view SASHELP.VCOLUMN is defined as:
select *
from DICTIONARY.COLUMNS;
2 describe view SAShelp.vTable;
NOTE: SQL view SASHELP.VTABLE is defined as:
select *
from DICTIONARY.TABLES;
This program lists the descriptions of all SQL Dictionary tables.
* name: describe-dictionaries;
PROC Contents data = sashelp.Class
out = Work.Contents;
PROC SQL; describe table Work.Contents;
describe table Dictionary.Dictionaries;
select distinct Memname as Memname,
catt('describe table Dictionary.'
,Memname
,';') as List
into :Memnames, :List separated by ' '
from Dictionary.Dictionaries;
&List.;
quit;
Speed Considerations
Here is the caveat on using PROC SQL dictionaries and SAShelp views. When you are in a production environment and there are many tables in libref Work, SQL begins to slow down, as shown by this program.
* name: create-tables-of-columns;
options fullstimer;
%Let Libname = SAShelp;
%Let Memname = Class;
DATA Work.Columns_view;
do until(EndoFile);
set SAShelp.Vcolumn
(where = ( Libname eq "%upcase(&Libname.)"
and Memname eq "%upcase(&Memname.)"))
end = EndoFile;
output;
end;
stop;
run;
PROC SQL; create table Work.Columns_SQL as
select *
from Dictionary.Columns
where Libname eq "%upcase(&Libname.)"
and Memname eq "%upcase(&Memname.)";
quit;
Proc Contents data = &Libname..&Memname
out = Work.Columns_Contents;
run;
Log:
NOTE: There were 5 observations read from the data set SASHELP.VCOLUMN.
WHERE (Libname='SASHELP') and (Memname='CLASS');
NOTE: The data set WORK.COLUMNS_VIEW has 5 observations and 18 variables.
NOTE: DATA statement used (Total process time):
real time 1:22.48
user cpu time 1.45 seconds
system cpu time 10.70 seconds
Memory 952k
NOTE: Table WORK.COLUMNS_SQL created, with 5 rows and 18 columns.
NOTE: PROCEDURE SQL used (Total process time):
real time 0.21 seconds
user cpu time 0.01 seconds
system cpu time 0.06 seconds
Memory 186k
NOTE: The data set WORK.COLUMNS_CONTENTS has 5 observations and 40 variables.
NOTE: PROCEDURE CONTENTS used (Total process time):
real time 0.87 seconds
user cpu time 0.01 seconds
system cpu time 0.04 seconds
Memory 151k
%Let Libname = SAShelp;
%Let Memname = Class;
PROC Copy in = SAShelp
nolist
out = Work;
run;
PROC SQL; create table Work.Columns_SQL as
select *
from Dictionary.Columns
where Libname eq "%upcase(&Libname.)"
and Memname eq "%upcase(&Memname.)";
quit;
The log:
NOTE: Table WORK.COLUMNS_SQL created, with 5 rows and 18 columns.
27 quit;
NOTE: PROCEDURE SQL used (Total process time):
real time 1.23 seconds
user cpu time 0.00 seconds
system cpu time 0.01 seconds
Memory 186k
Naming Conventions
SQL Dictionaries use the following Naming Conventions.
- data:
- Libname
- Memname
- variable:
- Name
Proc Contents output data set is the recommended list of variable names.
See usage in SmryEachVar_A_Data_Review_Suite
This suite uses the word Value for a list of values within a variables.
The following programs use four global macro variables:
- Libname
- Memname
- Name
- Value
Templates for Testing
PutGlobal
* name: PutGlobal.sas; %Put _global_;
Subroutine Template
* name: subroutine-demo;
PROC DoThis data = &Libname..&MemName.
(where = (&Name. eq "&Value."));
verb &Name.;
title2 "&Libname..&Memname..&Name.: &Value.";
run;
Subroutine: Print Subset
* name: print-subset;
PROC Print data = &Libname..&Memname.
(where = (&Name. = "&Value"));
title2 "&Libname..&Memname..&Name.: &Value.";
run;
Subroutine: Make Unique Freq
from the paper: http://www2.sas.com/proceedings/forum2007/113-2007.pdf ,section 2: Making Lists
* name: MuName-freq.sas: make unique Name freq;
PROC Freq data = &Libname..&Memname.;
tables &Name.
/ list missing noprint
out = Work.&Name.s;
run;
See also: Making_Lists#Make_List_of_Subsets
Subroutine: Make Unique Sort
* name: MuName-sort.sas: make unique Name sort;
PROC Sort data = &Libname..&Memname.
out = &MuOut.
(keep = &Name.)
nodupkey;
by &Name.;
run;
Templates for Programs
Print SAShelp.Classs Gender
* name: print-class-gender; *options source2;* Testing; * set parameters for subroutines; %Let Libname = sashelp; %Let Memname = Class; %Let Name = Sex; %Let MuOut = Work.&Name.s; * make list; %Include SiteIncl(MuName-sort); options source2 obs = 2;* Testing; * process list; %Let CxData = Work.Sexs(rename = (Sex = Value)); %Let CxInclude = Project(print-subset); %Include SiteIncl(CallXinc); %symdel Libname Memname Name; %symdel CxData CxInclude;
Print SAShelp.Shoes Region
* name: print-shoes-region-caller;
*options source2;* Testing;
* set parameters for subroutines;
%Let Libname = sashelp;
%Let Memname = Shoes;
%Let Name = Region;
%Let MuOut = Work.&Name.s;
* make list;
%Include SiteIncl(MuName-sort);
options source2 obs = 2;* Testing;
* process list;
%Let CxData = Work.&Name.s
(rename = (&Name. = Value));
%Let CxInclude = Project(print-subset);
%Include SiteIncl(CallXinc);
%symdel Libname Memname Name;
%symdel CxData CxInclude;
Example Application
from the paper: http://www2.sas.com/proceedings/forum2007/113-2007.pdf
Proc Report SAShelp.Shoes
/* name: Report-Region-include.sas
from : List Processing Basics
Creating and Using Lists of Macro Variables
Ronald J. Fehd and Art Carpenter
http://www2.sas.com/proceedings/forum2007/113-2007.pdf
usage :
%Let Libname = sashelp;
%Let Memname = Shoes;
%Let Name = Region;
%Let Value = Africa;
%Let OutPath = ;%*here: same folder*;
* fix Region = Central America/Caribbean;
* change slash to hyphen;
**** ******* */
%Let Filename = %sysfunc(translate(&Value.,-,/));
ods html file = "&OutPath.&Filename..html"
style = journal;
PROC Report data = &Libname..&Memname.
(where =(&Name. = "&Value."))
nowindows;
Title2 "Sales in &Value.";
Title3 "&Libname..&Memname..&Name.: &Value.";
column Product Subsidiary, Sales;
define Product / group;
define Subsidiary / across;
define Sales / analysis '';
run;
ods html close;
run;
%symdel Filename;
List Processing Module: Proc Report SAShelp.Shoes
* name: Report-Region-include-caller;
*options source2;* Testing;
* set parameters for subroutines;
%Let Libname = sashelp;
%Let Memname = Shoes;
%Let Name = Region;
%Let OutPath = ;
* make list;
%Include SiteIncl(MuName-sort);
options source2 obs = 2;* Testing;
* process list;
%Let CxData = Work.&Name.s
(rename = (&Name. = Value));
%Let CxInclude = Project(Report-Region-include);
%Include SiteIncl(CallXinc);
%symdel CxData CxInclude OutPath;
References
Hands On Workshop, SAS Global Forum, 2007
- SmryEachVar_A_Data_Review_Suite Best Contributed Paper, SAS Global Forum, 2008
- Journeymens_Tools
--macro maven == the radical programmer 10:55, 30 October 2008 (EDT)
- This page was last modified 22:20:29, 2008-11-12.
- This page has been accessed 214 times as of 2008-Nov-12.
- This page was last modified 22:30:50, 2008-11-12.
- This page has been accessed 1,471 times as of 2008-Dec-05.
- This page was last modified 22:26:32, 2008-12-22.
- This page has been accessed 3,217 times.
