Published on :
Macro EXTERNAL

AHGworkout Macro: Copying and Filtering Tables

This code is also available in: Deutsch Español Français
Awaiting validation
This macro automates the copying of SAS© tables. It accepts a source library (fromlib) and a list of tables (dsns). If the list is empty, it attempts to populate it automatically via an external macro (%AHGdsnInLib). For each table, it generates a Data Step that copies the data to the target library (tolib), optionally adding a prefix (pre) to the table name and applying a WHERE filter.
Data Analysis

Type : EXTERNAL


Data is read from the library specified by the macro parameter &fromlib. The code depends on user macros not provided here (AHGblank, AHGdsnInLib, AHGcount).

1 Code Block
DATA STEP Data
Explanation :
Macro definition. It uses a %DO loop to iterate over the list of tables and dynamically generate DATA steps to perform copying and filtering.
Copied!
1%macro AHGworkout(fromlib,dsns,tolib=work,pre=,where=%str(where 1));
2 %IF %AHGblank(&dsns) %THEN %AHGdsnInLib(lib=&fromlib,list=dsns,lv=1);;
3/* data &tolib..*/
4 %local i;
5 %DO i=1 %to %AHGcount(&dsns);
6 DATA &tolib..&pre%scan(&dsns,&i);
7 SET &fromlib..%scan(&dsns,&i);
8 &where ;
9 RUN;
10 %END;
11 
12%mend;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.