As the first step in the decommissioning of sasCommunity.org the site has been converted to read-only mode.


Here are some tips for How to share your SAS knowledge with your professional network.


Creating a SAS Data Set with Another Operating Systems Data Representation

From sasCommunity
Jump to: navigation, search

You can create a SAS data set in another operating system's internal data representation format. For example, you might be running SAS on Windows and want to create a UNIX SAS data set in a Windows directory for later delivery to a UNIX system. You can do this using either the OUTREP data set option or the OUTREP LIBNAME option. Here is an example of both options:

options msglevel=I;

/* Two examples of using the OUTREP LIBNAME option */

libname UNIXDATA "C:\TEMP\UNIXDATA" outrep=hp_ux;

/* 1. Creating a new SAS data set in the "Foreign" data library */

data UNIXDATA.class;
set  sashelp.class;
run;

proc contents data=UNIXDATA.class;
run;

/* 2. Copying a SAS data set to the "Foreign" data library */

proc copy in=sashelp out=UNIXDATA noclone;
	select prdsale;
run;

proc contents data=UNIXDATA.prdsale;
run;

/* Example of using the OUTREP data set option */

libname UNIXDATA clear;

libname UNIXDATA "C:\TEMP\UNIXDATA";

data UNIXDATA.orsales(outrep=hp_ux);
set  sashelp.orsales;
run;

proc contents data=UNIXDATA.orsales;
run;

In the first LIBNAME OUTREP option example, the newly created CLASS data set will be in HP-UX format, even thought it is stored in a Windows directory. Check the Data Representation field in the CONTENTS listing to verify that the CLASS SAS data set is indeed in HP-UX format.

In the second LIBNAME OUTREP option example, the PRDSALE data set will be in HP-UX format. But, when the COPY procedure is executed, SAS normally "CLONE"-s the format of the input data set to the output data set; which would result in another Windows SAS data set. So, you need to use the NOCLONE option for the new data set (UNIXLIB.PRDSALE) to be in HP-UX format.

The final example illustrates how you can code OUTREP data set option to store UNIXDATA.ORSALES as a UNIX SAS data set, even though it is stored in a Windows directory--as specified in the LIBNAME statement.

Note that with the MSGLEVEL=I option enabled, you will see the following type of message in your SAS log:

INFO: Data file UNIXDATA.CLASS.DATA is in a format that is native to another host, or the file encoding does not match the session encoding. Cross Environment Data Access will be used, which might require additional CPU resources and might reduce performance.

…that will let you know that you have, indeed, been successful in storing a SAS data set in a foreign hosts data representation.


Submitted by Michael A. Raithel, The man who wrote the book on performance. Contact me at my Discussion Page.