Sample 34513: Obtain the name of data set being read with SET statement with INDSNAME= option
Prior to SAS 9.2, in order to obtain the name of the data set being read from a SET statement, the IN= data set option is required, along with hard coding the value.
Beginning in SAS 9.2, the INDSNAME= option placed on the SET statement makes the process much easier. See the examples under the "Full Code" tab.
Prior to SAS 9.2, a new variable is created for each data set with
the IN= data set option. This variable has a value of 1 when the
current data set is being read. The IF and ELSE statements determine
the value for DSETNAME.
/* sample data sets */
data one;
x=1;
run;
data two;
y=2;
run;
data new;
set one(in=ina) two(in=inb);
if ina then dsetname='WORK.ONE';
else dsetname='WORK.TWO';
proc print;
run;
As of SAS 9.2, the INDSNAME= option for the SET statement writes
the name of the currently read data set to the variable name
specified. This isn't written to the data set by default, so a new
variable is created to hold DSN.
data one;
x=1;
run;
data two;
y=2;
run;
data new;
set one two indsname=dsn;
dsetname=dsn;
run;
Prior to 9.2
Obs x y dsetname
1 1 . WORK.ONE
2 . 2 WORK.TWO
As of 9.2
Obs x y dsetname
1 1 . WORK.ONE
2 . 2 WORK.TWO
| Type: | Sample |
| Topic: | SAS Reference ==> Statements ==> File-handling ==> SET Common Programming Tasks ==> Reading and Writing SAS Data
|
| Date Modified: | 2009-01-20 13:03:40 |
| Date Created: | 2009-01-16 13:05:35 |
Operating System and Release Information
| SAS System | Base SAS | z/OS | 8.2 TS2M0 | |
| OpenVMS VAX | 8.2 TS2M0 | |
| OS/2 | 8.2 TS2M0 | |
| Microsoft Windows 95/98 | 8.2 TS2M0 | |
| Microsoft Windows 2000 Advanced Server | 8.2 TS2M0 | |
| Microsoft Windows 2000 Datacenter Server | 8.2 TS2M0 | |
| Microsoft Windows 2000 Server | 8.2 TS2M0 | |
| Microsoft Windows 2000 Professional | 8.2 TS2M0 | |
| Microsoft Windows NT Workstation | 8.2 TS2M0 | |
| Microsoft Windows Server 2003 Datacenter Edition | 8.2 TS2M0 | |
| Microsoft Windows Server 2003 Enterprise Edition | 8.2 TS2M0 | |
| Microsoft Windows Server 2003 Standard Edition | 8.2 TS2M0 | |
| Microsoft Windows XP Professional | 8.2 TS2M0 | |
| Windows Millennium Edition (Me) | 8.2 TS2M0 | |
| 64-bit Enabled AIX | 8.2 TS2M0 | |
| 64-bit Enabled HP-UX | 8.2 TS2M0 | |
| 64-bit Enabled Solaris | 8.2 TS2M0 | |
| ABI+ for Intel Architecture | 8.2 TS2M0 | |
| AIX | 8.2 TS2M0 | |
| HP-UX | 8.2 TS2M0 | |
| IRIX | 8.2 TS2M0 | |
| Linux | 8.2 TS2M0 | |
| OpenVMS Alpha | 8.2 TS2M0 | |
| Solaris | 8.2 TS2M0 | |
| Tru64 UNIX | 8.2 TS2M0 | |