Home > Data Services > Catalog . Restricted Data . Census . ACS

Search Data Services

Meta Search
search across all the following databases:

Data Catalog
Data and documentation

KnowledgeBase
Common questions and answers.

Resources
Entire collection of data resources.


Latest Data News

RSS Feed icon

Lessons from North of the Border

Nerd Alert: Dictionary of Numbers

International Migration Statistics for the US

Open Data Executive Order

Measuring Marriage & Divorce among Same-Sex Couples

Using Wild Cards to Read Multiple Files

When a user wants to run multiple files through the same data steps, the use of wild cards can save on the number of commands required to process those steps on each file. Below is an example of reading and processing multiple files using standard coding.

options linesize=70 pagesize=52 noovp compress=yes;
filename raw68 PIPE 'zcat
 /usr/data/public/us/government/cps/october/uniform/1968.Z';
filename raw69 PIPE 'zcat
 /usr/data/public/us/government/cps/october/uniform/1969.Z';
data temp68;
   infile raw68 lrecl=283;
   input
       yr 15-16
       age 26-27
       state 56-57
       yrenr 86-87;
  if yrenr ne 20 then delete;
  proc freq;
   tables age;
data temp69;
   infile raw69 lrecl=283;
   input
       yr 15-16
       age 26-27
       state 56-57
       yrenr 86-87;
if yrenr ne 20 then delete;
proc freq;
 tables age;
run;

The use of wildcard characters allows the system to identify files using pattern matching. The following program will read and process the same data in fewer steps. Note the wildcard characters (?) in bold. Each wild character '?' is representative of any possible character (i.e., four wild characters '????' symbolizes any four letter file.)

options linesize=70 pagesize=52 noovp compress=yes;
filename rawall PIPE 'zcat
/usr/data/public/us/government/cps/october/uniform/19??.Z';
data tempall;
   infile rawall lrecl=283;
   input
        yr 15-16
        age 26-27
        state 56-57
        yrenr 86-87;
if yrenr ne 20 then delete;
proc freq;
  tables age;
run;

A different wild card character that is very useful is the asterick (*). This behaves differently from the wild '?' character. You do not have to have an asterick for every character you are trying to match with. The asterick can represent a single character or a string of characters. Below are a few examples showing how the wild (*) can be used.

 
 filename rawall PIPE 'zcat /usr/..../uniform/19*.Z';
In the command line above every file that begins with the characters '19' and has the .Z extention will match the file pattern.
 filename rawall PIPE 'zcat /usr/..../uniform/*90*';

Here, every filename containing the '90' string matches this pattern.