Valid in: | DATA step |
Category: | File-handling |
Type: | Executable |
Instead of using a data set name, you can specify the physical pathname to the file, using syntax that your operating system understands. The pathname must be enclosed in single or double quotation marks.
Performing a Table Lookup When the Master File Contains Duplicate Observations
Unless previously defined, the length of the variable is set to 41 bytes. Use a LENGTH statement to make the variable length long enough to contain the value of the physical filename if the filename is longer than 41 bytes.
If the variable is previously defined as a character variable with a specific length, that length is not changed. If the value placed into the INDSNAME variable is longer than that length, then the value is truncated.
If the variable is previously defined as a numeric variable, an error will occur.
The variable is available in the DATA step, but the variable is not added to any output data set.
You cannot use POINT= with KEY=.
The POINT= variable is available anywhere in the DATA step, but it is not added to any new SAS data set.
Reading a Subset by Using Direct Access
If the KEY= value does not change on successive executions of the SET statement, the search begins by following the most recently retrieved observation. In other words, when consecutive duplicate KEY= values appear, the SET statement attempts a one-to-one match with duplicate indexed values in the data set that is being read. If more consecutive duplicate KEY= values are specified than exist in the data set that is being read, the extra duplicates are treated as not found.
When KEY= is a unique value, only the first attempt to read an observation with that key value succeeds; subsequent attempts to read the observation with that value of the key will fail. The _IORC_ variable returns a value that corresponds to the SYSRC autocall macro's mnemonic _DSENOM. If you add the /UNIQUE option, subsequent attempts to read the observation with the unique KEY= value will succeed. The _IORC_ variable returns a 0.
set SALES1:;
tells
SAS to read all data sets starting with "SALES1" such as SALES1, SALES10,
SALES11, and SALES12.
sales1 sales2 sales3 sales4 sales1-sales4
data fitness; set health exercise well; run;
data combine; set invtory(keep=partno instock price); set partcode(keep=partno desc) key=partno; run;
data combine; set partcode(keep=partno new_stk); set invtory(keep=partno instock price) key=partno/unique; instock=instock+new_stk; run;
/* Create some data sets to read */ data gas_price_option; value=395; run; data gas_rbid_option; value=840; run; data gas_price_forward; value=275; run; /* Create a data set D */ data d; set gas_price_option gas_rbid_option gas_price_forward indsname=dsn; /* split the data set names into 3 parts */ commodity = scan (dsn, 2, "._"); type = scan (dsn, 3, "._"); instrument = scan (dsn, 4, "._"); run; proc print data=d; run;
data dept008; emp=13; run; data dept009; emp=9; run; data dept010; emp=4; run; data dept011; emp=33; run; data _null_; set dept008-dept010; put _all_; run;
1 data dept008; emp=13; run; NOTE: The data set WORK.DEPT008 has 1 observations and 1 variables. NOTE: DATA statement used (Total process time): real time 0.06 seconds cpu time 0.03 seconds 2 data dept009; emp=9; run; NOTE: The data set WORK.DEPT009 has 1 observations and 1 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds 3 data dept010; emp=4; run; NOTE: The data set WORK.DEPT010 has 1 observations and 1 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds 4 data dept011; emp=33; run; NOTE: The data set WORK.DEPT011 has 1 observations and 1 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds 5 6 data _null_; 7 set dept008-dept010; 8 put _all_; 9 run; emp=13 _ERROR_=0 _N_=1 emp=9 _ERROR_=0 _N_=2 emp=4 _ERROR_=0 _N_=3 NOTE: There were 1 observations read from the data set WORK.DEPT008. NOTE: There were 1 observations read from the data set WORK.DEPT009. NOTE: There were 1 observations read from the data set WORK.DEPT010. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds
data dept008; emp=13; run; data dept009; emp=9; run; data dept011; emp=4; run; data dept014; emp=33; run; data _null_; set dept008-dept014; put _all_; run;
1 data dept008; emp=13; run; NOTE: The data set WORK.DEPT008 has 1 observations and 1 variables. NOTE: DATA statement used (Total process time): real time 0.04 seconds cpu time 0.04 seconds 2 data dept009; emp=9; run; NOTE: The data set WORK.DEPT009 has 1 observations and 1 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds 3 data dept011; emp=4; run; NOTE: The data set WORK.DEPT011 has 1 observations and 1 variables. NOTE: DATA statement used (Total process time): real time 0.03 seconds cpu time 0.01 seconds 4 data dept014; emp=33; run; NOTE: The data set WORK.DEPT014 has 1 observations and 1 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds 5 data _null_; 6 set dept008-dept014; ERROR: File WORK.DEPT010.DATA does not exist. ERROR: File WORK.DEPT012.DATA does not exist. ERROR: File WORK.DEPT013.DATA does not exist. 7 put _all_; 8 run; NOTE: The SAS System stopped processing this step because of errors. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds