Sample 35884: Creating smaller data sets from a large data set
Communications software such as FTP can be used to move SAS data sets and transport files in binary mode. However, you might find the file too large to transfer efficiently. The network might not hold up for the entire process or the transfer might take too long.
This macro can be used to break the data set into smaller data sets at the source host before the transport process. Parameters include the data set name and number of data sets you want to create.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
This macro can be used to break a data set into smaller data sets. Parameters include the data set name and number of data sets you want to create. In this example, we are generating four data sets from the SASHELP.CLASS data set. Three data sets contain four observations and the fourth data set contains the remaining seven observations.
%macro test(dsn,obs);
%let dsid=%sysfunc(open(&dsn));
%let num=%sysfunc(attrn(&dsid,nobs));
%let rc=%sysfunc(close(&dsid));
%let end=%sysevalf(&num/&obs,integer);
%local newobs;
%do i = 1 %to &end;
%if &i = 1 %then %do;
data x&i;
set &dsn(firstobs=&i obs=&obs);
run;
%end;
%else %do;
%if &i ne &end %then %do;
%let newobs=&newobs+&obs;
data x&i;
set &dsn(firstobs=%eval(&newobs+1) obs=%eval(&obs*&i));
run;
%end;
%else %do;
%let newobs=&newobs+&obs;
data x&i;
set &dsn(firstobs=%eval(&newobs+1));
run;
%end;
%end;
%end;
%mend test;
%test(sashelp.class,4)
/* After running the sample, you can uncomment the PROC DATASETS */
/* code below and remove all data sets from the WORK library. */
/*proc datasets lib=work kill memtype=data;*/
/*quit;*/
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
Creating smaller data sets from one large data set can be useful, especially if you have a large file for data transfer. This macro allows you to pass in the data set name and number of data sets you want to create.
| Date Modified: | 2009-06-25 10:23:59 |
| Date Created: | 2009-05-11 19:19:10 |
Operating System and Release Information
| SAS System | N/A | Microsoft Windows Server 2003 Datacenter 64-bit Edition | | |
| Microsoft® Windows® for 64-Bit Itanium-based Systems | | |
| Macintosh on x64 | | |
| Microsoft Windows 2000 Professional | | |
| Macintosh | | |
| z/OS | | |
| OpenVMS VAX | | |
| Microsoft Windows Server 2003 Enterprise 64-bit Edition | | |
| Microsoft Windows XP 64-bit Edition | | |
| Microsoft® Windows® for x64 | | |
| OS/2 | | |
| Microsoft Windows 95/98 | | |
| Microsoft Windows 2000 Advanced Server | | |
| Microsoft Windows 2000 Datacenter Server | | |
| Microsoft Windows 2000 Server | | |
| Microsoft Windows NT Workstation | | |
| Microsoft Windows Server 2003 Datacenter Edition | | |
| Microsoft Windows Server 2003 Enterprise Edition | | |
| Microsoft Windows Server 2003 Standard Edition | | |
| Microsoft Windows Server 2008 | | |
| Microsoft Windows XP Professional | | |
| Windows Millennium Edition (Me) | | |
| Windows Vista | | |
| 64-bit Enabled AIX | | |
| 64-bit Enabled HP-UX | | |
| 64-bit Enabled Solaris | | |
| ABI+ for Intel Architecture | | |
| AIX | | |
| HP-UX | | |
| HP-UX IPF | | |
| IRIX | | |
| Linux | | |
| Linux for x64 | | |
| Linux on Itanium | | |
| OpenVMS Alpha | | |
| OpenVMS on HP Integrity | | |
| Solaris | | |
| Solaris for x64 | | |
| Tru64 UNIX | | |