Casformats
Casformats
Casformats
SAS® Documentation
March 13, 2020
The correct bibliographic citation for this manual is as follows: SAS Institute Inc. 2019. SAS® Cloud Analytic Services 3.5: User-Defined
Formats. Cary, NC: SAS Institute Inc.
SAS® Cloud Analytic Services 3.5: User-Defined Formats
Copyright © 2019, SAS Institute Inc., Cary, NC, USA
1
About User-Defined Formats
Information about working with user-defined formats on the SAS client are described
in FORMAT procedure. The information in this section covers how to work with user-
defined formats with SAS Cloud Analytic Services.
A format library has a name and can be temporary (session-scope) for the duration
of your programming session. The alternative is that it can be set to have global
scope and exist for as long as the server is running. You can persist a format library
in a SASHDAT file and you can add formats to your CAS session from a persisted
file.
Your administrator can configure the server so that the following occur when the
server starts:
n format libraries are added and promoted from persisted format libraries (libraries
that are persisted as SASHDAT files in a caslib's data source).
n during session start up for each connection, the format search path is updated to
include the format libraries.
2 Chapter 1 / About User-Defined Formats
For information about how to perform common tasks related to user-defined formats
in SAS Cloud Analytic Services, see “Manage Your User-Defined Formats” on page
4.
2
Using User-Defined Formats In SAS
Cloud Analytic Services
SAS Log . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Key Ideas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Drop a Format Library from Session Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
SAS Log . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Key Ideas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Table 2.1 Performing Common Tasks for User-Defined Formats Using the FORMAT Procedure and CAS
Statement
Add a new format to SAS and Use the FORMAT procedure “Add and Save a User-Defined
SAS Cloud Analytic Services. with the CASFMTLIB= option. Format” (p. 6)
Display your format search list. Use a CAS statement with the “List Format Libraries, Formats, and
LISTFMTSEARCH option. Search List” (p. 12)
List the format libraries that are Use a CAS statement with the “List Format Libraries, Formats, and
available. LISTFORMATS option. Search List” (p. 12)
Add a global format library to Use a CAS statement with the “Add a Global Format Library to a
your format search list. FMTSEARCH option. Session’s Format Search List” (p. 27)
List the format names in all Use a CAS statement with the “List Format Libraries, Formats, and
format libraries. LISTFORMATS and MEMBERS Search List” (p. 12)
options.
Manage Your User-Defined Formats 5
Copy existing SAS format Do one of the following: “Migrate User-Defined Formats from
catalogs to a SAS Cloud Analytic SAS To CAS” (p. 18)
n Use the FORMAT procedure
Services format library.
to write information about
formats in a format catalog to
a temporary SAS data set,
and then to read the format
information from the
temporary data set into a
CAS format library.
n Use the FMTC2ITM
procedure to copy the SAS
user-defined format catalogs
to an item-store file, and then
use a CAS statement with the
ADDFMTLIB and the PATH=
options to add the formats in
the item-store file to a CAS
format library.
Copy only the formats that are Do the following: “Add Formats Referenced in a Single
referenced in data sets stored in SAS Library to a CAS Session” (p.
n Use the %UDFSEL macro on
a single SAS library to a SAS 21)
page 6 to create a
Cloud Analytic Services format
SELECT statement for all
library.
user-defined formats
referenced in the library.
n Use the FORMAT procedure
to get format data using the
SELECT statement and to
store the data in a table.
n Use the FORMAT procedure
to copy the format data table
to a SAS Cloud Analytic
Services format library.
Persist a format library as a Use a CAS statement with the “Add and Save a User-Defined
SASHDAT file. SAVEFMTLIB and TABLE Format” (p. 6)
options, and, if needed, the
CASLIB option.
Add a format library that is stored Use the CAS statement with the “Add a Format Library from a File” (p.
in a SASHDAT file. ADDFMTLIB and TABLE 9)
options, and, if needed, the
CASLIB option.
6 Chapter 2 / Using User-Defined Formats In SAS Cloud Analytic Services
Drop a format library from Use the CAS statement with the “Drop a Format Library from Session
session scope. DROPFMTLIB and Scope” (p. 29)
FMTLIBNAME options.
Example
/* options cashost="cloud.example.com" casport=5570; */
cas casauto sessopts=(caslib="casuser"); /* 1 */
proc casutil;
format enginesize enginesize.; /* 4 */
load data=sashelp.cars casout="cars" replace;
contents casdata="cars";
run;
quit;
proc casutil; /* 7 */
save casdata="cars" casout="cars_formatted" replace;
droptable casdata="cars";
run;
quit;
Results
The following display shows the partial results for the CONTENTS statement in the
CASUTIL procedure. The results show that the EngineSize column uses the
Enginesize format.
Figure 2.1 Partial Results for the CONTENTS Statement of the CASUTIL Procedure
The following display shows the first few columns from the Mpg_hwy_by_size table.
Key Ideas
n Use the FORMAT procedure with the CASFMTLIB= option to add formats to your
CAS session automatically.
n You can save all the formats in a format library in a SASHDAT file with the CAS
statement and the SAVEFMTLIB option. Only caslibs with path-based data sources
such as PATH, DNFS, and HDFS can be used.
n After you have saved your formats to a SASHDAT file, you can do the following:
Prerequisites
Before you run the code in this example, you must do the following in order to get
the correct results:
1 If you have not already done so, run the code in “Add and Save a User-Defined
Format”.
3 Drop format library Casformats from the current SAS Cloud Analytic Services
session.
cas casauto dropfmtlib fmtlibname=casformats;
Example
When you use the CAS statement with the SAVEFMTLIB option, you create a
SASHDAT file that includes the formats in a format library. One requirement is that
you specify a caslib with a data source type that supports saving files. The data
source types are PATH, DNFS, and HDFS.
10 Chapter 2 / Using User-Defined Formats In SAS Cloud Analytic Services
This example shows the reverse of that process, adding a format library from a
SASHDAT file.
cas casauto addfmtlib fmtlibname=fmtlib1 /* 1 */
caslib=casuser
table=enginefmt;
proc casutil; /* 2 */
contents casdata="cars_formatted.sashdat";
load casdata="cars_formatted.sashdat"
casout="cars_formatted";
run;
quit;
1 The CAS statement ADDFMTLIB option adds a format library to the active CAS
session. The file, Enginefmt.sashdat, is specified in the TABLE= option. The file
is relative to the path for the CASUSER caslib.
2 The CAS procedure CONTENTS statement specifies the on-disk name,
Cars_formatted.sashdat. As a result, the column information shows that the
format Enginesize was associated with column Enginesize when the table was
saved.
3 Because the Enginesize format has five values and the VAR statement specifies
two columns, the MDSUMMARY procedure creates an output table,
Weight_len_by_size, with 10 rows.
4 The SORT procedure sorts the results from the MDSUMMARY procedure by
columns _Column_ and Enginesize. The sorted data is stored in table
Work.Weight_len_by_size_sorted.
5 The PRINT procedure prints the sorted data by column _Column_.
Results
The following display shows the results of the PRINT procedure. The rows are
grouped by the two different values of _Column_.
Add a Format Library from a File 11
Key Ideas
n Formats added with the CAS statement are added to SAS Cloud Analytic Services,
but not to SAS. If you want to add formats to both SAS Cloud Analytic Services and
SAS, use the FORMAT procedure as shown in “Add and Save a User-Defined
Format” on page 6.
n Use the CASLIB option in the CAS statement if the file is not in the active caslib.
The caslib must have a path-based data source, such as PATH, DNFS, or HDFS.
n Use the TABLE option in the CAS statement if the name of the file on disk is
different from the name specified in the FMTLIBNAME option.
n By default, the format library is appended to the session’s format search list.
Include the POSITION option in the CAS statement to specify a different location in
the format search list.
n By default, the format library is added in session scope. Include the PROMOTE
option in the CAS statement if you also want to promote the format library.
12 Chapter 2 / Using User-Defined Formats In SAS Cloud Analytic Services
Example
/* options cashost="cloud.example.com" casport=5570; */
cas casauto; /* 1 */
7 The LISTFMTSEARCH option displays the format libraries that are in the search
list. In this example, because the Casformats library was dropped, but the
FMTSEARCHREMOVE option was not used, the name remains in the search
list. "Not Found" is used to indicate that Casformats is not available as a
session-scope or global-scope format library.
14 Chapter 2 / Using User-Defined Formats In SAS Cloud Analytic Services
SAS Log
1 cas casauto;
...
2
3 proc format lib=work.formats casfmtlib="casformats";
NOTE: Both CAS based formats and catalog-based formats will be written.
The CAS based formats will be written to the session CASAUTO.
4 value ynm
5 1='yes'
6 2='no'
7 3='maybe';
NOTE: Format library CASFORMATS added. Format search update using
parameter APPEND completed.
NOTE: Format YNM has been output.
8 run;
...
9
10 proc format lib=work.formats casfmtlib="fmtlib2";
NOTE: Both CAS based formats and catalog-based formats will be written.
The CAS based formats will be written to the session CASAUTO.
11 value sml
12 1='small'
13 2='medium'
14 3='large';
NOTE: Format library FMTLIB2 added. Format search update using parameter APPEND
completed.
NOTE: Format SML has been output.
15 run;
...
16
17 cas casauto listformats members;
NOTE: Fmtlib = CASFORMATS
Scope = Session
Fmtsearch = YES
Format = ynm
NOTE: Fmtlib = FMTLIB2
Scope = Session
Fmtsearch = YES
Format = sml
NOTE: Request to LISTFORMAT completed for session CASAUTO.
18
19 cas casauto listfmtranges fmtname=ynm;
Format Name Range
YNM 1=yes
2=no
3=maybe
NOTE: Request to LISTFMTRANGES YNM completed for session CASAUTO.
20
21 cas casauto dropfmtlib fmtlibname=casformats;
NOTE: Request to DROPFMTLIB CASFORMATS completed for session CASAUTO.
22
23 cas casauto listfmtsearch;
NOTE: FmtLibName = CASFORMATS
Scope = Not Found
NOTE: FmtLibName = FMTLIB2
Scope = Session
NOTE: Request to LISTFMTSEARCH completed for session CASAUTO.
Add Locale-Specific Format Libraries 15
Key Ideas
n When you use the FORMAT procedure with the CASFMTLIB= option, the format
library and formats are automatically made available to your CAS session.
n Use the LISTFMTSEARCH option in a CAS statement to display the format
libraries that are in the search list.
n You can print a brief view of format values in the SAS log with the CAS statement
LISTFMTRANGES and FMTNAME= options. The format name that you specify
must be in the search list.
Example
/* options cashost="cloud.example.com" casport=5570; */
cas casauto; /* 1 */
options locale=fr_FR; /* 3 */
proc format locale library=work.formats casfmtlib="casformats";
value setting
20.5 - HIGH = 'Haute'
10.5 - <20.5 = 'Moyen'
LOW - <10.5 = 'Bas';
run;
options locale=en_US;
2 The PROC FORMAT step includes the LOCALE option, which specifies to create
a locale-specific format in the format catalog. In this procedure step, the default
locale is used, which is en_US in this example.
3 The OPTIONS statement sets the locale for the SAS client to French. The
subsequent PROC FORMAT step creates a format that corresponds to the
current SAS locale, fr_FR, in the format catalog. The range values must be
specified using a period as the decimal point. Otherwise, a syntax error occurs. It
will be demonstrated later that the decimal range values are displayed
appropriately in the French locale.
4 The CAS statement LISTFORMATS and MEMBERS options list the format
catalog, Casformats, and the format names, fr_fr-setting and en_us-setting, in
the SAS log.
5 The CAS statement SESSOPTS= option sets the CAS session locale to United
States English. The subsequent CAS statement prints a brief view of the format
values in the SAS log.
6 The CAS statement SESSOPTS= option sets the CAS session locale to French.
The subsequent CAS statement prints a brief view of the format values in the
SAS log. To display the appropriate format values for the French locale, SAS
automatically replaces the period with a comma for the decimal point in the
displayed range values. (See “SAS Log” on page 17.) This change occurs
regardless of the locale in which the format was created.
Add Locale-Specific Format Libraries 17
SAS Log
1 cas casauto;
...
2 options locale=en_US;
3 proc format locale library=work.formats casfmtlib="casformats";
NOTE: Both CAS based formats and catalog-based formats will be
written. The CAS based formats will be written to the session
CASAUTO.
4 value setting
5 20.5 - HIGH = 'High'
6 10.5 - <20.5 = 'Medium'
7 LOW - <10.5 = 'Low';
NOTE: Format library CASFORMATS added. Format search update using
parameter APPEND completed.
NOTE: Format SETTING has been written to WORK.FORMATS_en_US.
8 run;
...
9 options locale=fr_FR;
10 proc format locale library=work.formats casfmtlib="casformats";
NOTE: Both CAS based formats and catalog-based formats will be written.
The CAS based formats will be written to the session CASAUTO.
11 value setting
12 20.5 - HIGH = 'Haute'
13 10.5 - <20.5 = 'Moyen'
14 LOW - <10.5 = 'Bas';
NOTE: Format SETTING has been written to WORK.FORMATS_fr_FR.
15 run;
...
16 options locale=en_US;
17 cas casauto listformats members;
NOTE: Fmtlib = CASFORMATS
Scope = Session
Fmtsearch = YES
Format = en_us-setting
Format = fr_fr-setting
NOTE: Request to LISTFORMAT completed for session CASAUTO.
18 cas casauto sessopts=(locale="en_US");
NOTE: The CAS statement request to update one or more session
options for session CASAUTO completed.
19 cas casauto listfmtranges fmtname=setting;
Format Name Range
SETTING LOW-<10.5=Low
10.5-<20.5=Medium
20.5-HIGH=High
Key Ideas
n To create a locale-specific format, set SAS system option LOCALE to the desired
locale, and then include the LOCALE option in the FORMAT procedure statement.
n To use a locale-specific format, set session option LOCALE to the desired locale.
See Also
SAS National Language Support (NLS): Reference Guide
proc fmtc2itm /* 2 */
catalog=(work.formats orion.mailfmts)
itemstore="path-to-item-store-file";
run;
3 The CAS statement ADDFMTLIB option adds the formats in the item-store file
that was created by the FMTC2ITM procedure into CAS format library Myfmtlib.
The PATH= option specifies the path to the item-store file.
20 Chapter 2 / Using User-Defined Formats In SAS Cloud Analytic Services
4 The CAS statement LISTFORMAT option lists the formats in format library
Myfmtlib to the SAS log for verification.
Key Ideas
n Use the methods demonstrated in these examples to migrate your SAS user-
defined format catalogs to SAS Cloud Analytic Services.
n Use the FMTC2ITM procedure with the ITEMSTORE= option to write the formats in
one or more SAS format catalogs to an item-store file. By default all of the formats
in the specified catalogs are written to an item-store file. Use a SELECT statement
in the FMTC2ITM procedure step if you want to select a subset of the formats in
the input format catalogs. See “FMTC2ITM Procedure” in Base SAS Procedures
Guide.
n Use a CAS statement ADDFMTLIB option with PATH= to add the formats stored in
the item-store file into a CAS format library. The path that you specify must be
readable from the control node of the CAS server.
n If you have multiple SAS format catalogs to migrate, use the CATNAME statement
to combine the format catalogs into one format catalog.
n Use the FORMAT procedure to move the formats in a SAS format catalog to SAS
Cloud Analytic Services in two steps:
1 Get information about the formats from the format catalog, and then store
the information in a temporary SAS data set.
2 Copy the format data from the temporary format information data set to a
format library in SAS Cloud Analytic Services.
n If your SAS format catalogs are very large and you use the formats frequently,
consider saving the CAS format library to a SASHDAT file. Once you have saved it
to a file, you can add it to your future sessions, when needed, as shown in “Add a
Format Library from a File” on page 9.
Add Formats Referenced in a Single SAS Library to a CAS Session 21
Example
This example demonstrates how to use the %UDFSEL macro and the FORMAT
procedure to scan a single SAS library for references to user-defined formats, and
then to copy the formats that are being referenced to a SAS Cloud Analytic Services
format library. Unlike adding entire SAS format catalogs as shown in “Migrate User-
Defined Formats from SAS To CAS” on page 18, you can use this method to add
only the formats that you are using in your data. However, the %UDFSEL macro
scans data sets in only one library at a time. If your data sets are stored in multiple
libraries, you must perform the steps shown in this example for each library.
In this example, library Work contains one data set, Cars_Formatted. As shown in
the following output from the CONTENTS procedure, user-defined formats are
applied to columns EngineSize and Mpg_Highway.
Formats Enginsize and MPGrating exist in the Work.Formats catalog. The following
SAS program copies these formats to SAS Cloud Analytic Services format library
MyFmtLib.
/* options cashost="cloud.example.com" casport=5570; */
cas casauto; /* 1 */
%udfsel(work); /* 2 */
run;
Note: If your data uses formats in more than one format catalog, you can use a
CATNAME statement to combine the required format catalogs into one as was
done in “Migrate User-Defined Formats from SAS To CAS” on page 18.
4 Optional: The PRINT procedure prints columns FMTNAME, START, END, and
LABEL in table Fmtdata. This step enables you to verify that the format library
that is created in SAS Cloud Analytic Services is correct.
5 The FORMAT procedure reads the format data from table Fmtdata, and then
uses the data to create the formats in SAS Cloud Analytic Services format library
MyFmtLib.
6 Optional: The remaining CAS statements display the formats in format library
MyFmtLib and their ranges for verification. This step enables you to compare the
formats in MyFmtLib with the original format data. (See Output 2.1 on page 23
and “SAS Log” on page 23.)
Add Formats Referenced in a Single SAS Library to a CAS Session 23
Results
Output 2.1 Format Data in Table Fmtdata
SAS Log
Here is a partial listing of the program output that is written to the SAS log.
24 Chapter 2 / Using User-Defined Formats In SAS Cloud Analytic Services
Key Ideas
n Use the method demonstrated in this example to migrate only the SAS formats that
you are using in your data to SAS Cloud Analytic Services.
n Use the %UDFSEL on page 6 macro to generate a SELECT statement for the
formats that are referenced in the data sets in a single SAS library.
n Use the CATNAME statement to combine multiple format catalogs into one.
n Use the FORMAT procedure to move the formats to SAS Cloud Analytic Services
in two steps:
1 Get information about the selected formats from the format catalog, and
then store the information in a temporary SAS data set.
2 Copy the format data from the temporary SAS data set to a SAS Cloud
Analytic Services format library.
Example
/* options cashost="cloud.example.com" casport=5570; */
cas casauto; /* 1 */
added to the session’s format search list. See “Add a Global Format Library to a
Session’s Format Search List” on page 27.
SAS Log
1 cas casauto;
...
2
3 proc format lib=work.formats casfmtlib="myfmtlib";
NOTE: Both CAS based formats and catalog-based formats will be written.
The CAS based formats will be written to the session CASAUTO.
4 value abc
5 1 = 'yes'
6 2 = 'no'
7 3 = 'maybe'
8 ;
NOTE: Format library MYFMTLIB added. Format search update using
parameter APPEND completed.
NOTE: Format ABC has been output.
9 run;
...
10
11 cas casauto promotefmtlib fmtlibname=myfmtlib replace;
NOTE: Request to PROMOTEFMTLIB MYFMTLIB completed for session CASAUTO.
Key Ideas
n When you promote a format library from a programming session, the format library
is made available to all sessions that connect to that CAS server.
n When a format library is promoted, it is not automatically added to the format
search list of the other sessions on that server. To use format library MyFmtLib in
another session, it must be added to the session’s format search list. See “Add a
Global Format Library to a Session’s Format Search List” on page 27.
n If you save your format library to a SASHDAT file, your SAS Cloud Analytic
Services system administrator can configure the server to automatically add your
format library to the format search list of all sessions on that server. See “Add and
Save a User-Defined Format” on page 6 and Configuration File Options.
Add a Global Format Library to a Session’s Format Search List 27
Example
This example assumes that global format libraries CompanyFormats and
DeptFormats are added automatically at session start-up, and that format library
MyFmtLib already exists in global scope. The following program inserts format
library MyFmtLib at the beginning of session Casauto’s format search list and
creates MyFmtLib in session scope.
/* options cashost="cloud.example.com" casport=5570; */
cas casauto; /* 1 */
SAS Log
The SAS log for any session that runs the code to add the promoted format library
to the search list is similar to the following.
28 Chapter 2 / Using User-Defined Formats In SAS Cloud Analytic Services
1 cas casauto;
...
2
3 cas casauto listfmtsearch;
NOTE: FmtLibName = COMPANYFORMATS
Scope = Both
NOTE: FmtLibName = DEPTFORMATS
Scope = Both
NOTE: Request to LISTFMTSEARCH completed for session CASAUTO.
4
5 cas casauto listformats scope=global;
NOTE: Fmtlib = COMPANYFORMATS
Scope = Global
Fmtsearch = NA
NOTE: Fmtlib = DEPTFORMATS
Scope = Global
Fmtsearch = NA
NOTE: Fmtlib = MYFMTLIB
Scope = Global
Fmtsearch = NA
NOTE: Request to LISTFORMAT completed for session CASAUTO.
6
7 cas casauto fmtsearch=(myfmtlib) position=insert;
NOTE: Request to FMTSEARCH completed for session CASAUTO.
8
9 cas casauto listfmtsearch;
NOTE: FmtLibName = MYFMTLIB
Scope = Both
NOTE: FmtLibName = COMPANYFORMATS
Scope = Both
NOTE: FmtLibName = DEPTFORMATS
Scope = Both
NOTE: Request to LISTFMTSEARCH completed for session CASAUTO.
Key Ideas
n Use CAS statement options LISTFORMATS SCOPE=GLOBAL to list all of the
global format libraries that are available to the session.
n Use the FMTSEARCH= option to add one or more global format libraries to your
session’s format search list. Include the POSITION= option to specify whether the
new libraries are appended to the current path, are prepended to the current path,
or replace the current path.
n The global format libraries are added to your session in session scope.
Drop a Format Library from Session Scope 29
Example
This example assumes that global format libraries CompanyFormats and
DeptFormats are added automatically at session start-up. The following program
drops format library DeptFormats from session scope and removes it from the
format search list in session Casauto.
/* options cashost="cloud.example.com" casport=5570; */
cas casauto; /* 1 */
SAS Log
1 cas casauto;
...
2
3 cas casauto dropfmtlib fmtlibname=deptFormats
4 fmtsearchremove;
NOTE: The format library DEPTFORMATS was removed from the format search list.
NOTE: Request to DROPFMTLIB DEPTFORMATS completed for session CASAUTO.
5
6 cas casauto listformats;
NOTE: Fmtlib = COMPANYFORMATS
Scope = Session
Fmtsearch = YES
NOTE: Fmtlib = COMPANYFORMATS
Scope = Global
Fmtsearch = NA
NOTE: Fmtlib = DEPTFORMATS
Scope = Global
Fmtsearch = NA
NOTE: Request to LISTFORMAT completed for session CASAUTO.
7
8 cas casauto listfmtsearch;
NOTE: FmtLibName = COMPANYFORMATS
Scope = Both
NOTE: Request to LISTFMTSEARCH completed for session CASAUTO.
Key Ideas
n The format library must exist in the session’s format search list. Otherwise, an error
occurs.
n If the library exists in both global scope and session scope, the session-scope
library is dropped first. If you want to drop the global-scope format library as well,
issue the drop request again.
n By default, when you drop a format library, the format library name is not removed
from the session’s format search list. Use the REMOVEFMTSEARCH option in the
CAS statement to remove the dropped format library from the format search list.
31
3
Utility Macro for User-Defined
Formats
Dictionary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
%UDFSEL Autocall Macro . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Dictionary
Syntax
%UDFSEL (SAS-library-name);
Required Argument
SAS-library-name
specifies a single SAS library name.
32 Chapter 3 / Utility Macro for User-Defined Formats
Details
About the %UDFSEL Macro
The %UDFSEL macro scans the data sets in library SAS-library-name and
generates a SELECT statement for all of the unique non-intrinsic formats that are
referenced. The generated SELECT statement is written to Selstmt, which is a file
reference to a temporary file. You can then use the generated SELECT statement
with the FORMAT procedure to get information about the formats from a specified
format catalog and store the information in a SAS data set. After you have stored
the format data in a SAS data set, you can use the format data set with the
FORMAT procedure to copy the selected formats from SAS to a SAS Cloud Analytic
Services format library.
%macro udfsel(libref);
/* Note that this step make take a while due to the use of sashelp.vformat. */
*-----merge to determine what formats are not intrinsic and generate the SELECT statement-----*;
data _null_; merge &intrinsic_output.(in=is_intrinsic) &contents_output.(in=want) end=eof; by fmtname
file selstmt;
retain n_written 0;
if _n_=1 then put 'select';
if fmtname ne ' ' and want and not is_intrinsic then do;
n_written+1;
put fmtname;
end;
if eof then do;
if n_written = 0
then put 'date';
put ';';
end;
run;
%mend udfsel;
Example
%udfsel(work); /* 1 */
1 Macro %UDFSEL scans the data sets in the Work library, and then generates a
SELECT statement for all of the user-defined formats that are referenced. In this
example, Work.Cars_Summary is the only data set in the Work library. The
SELECT statement is written to file reference Selstmt. Here is a simple example
of the SELECT statement: select ENGINESIZE MPGRATING;
2 The FORMAT procedure uses the SELECT statement generated by the
%UDFSEL macro to get the format data from the Work.Formats catalog. The
%INCLUDE statement brings in the SELECT statement from file reference
34 Chapter 3 / Utility Macro for User-Defined Formats
Selstmt. The SOURCE2 option prints the SELECT statement to the SAS log.
The FORMAT procedure then stores the format data in table Work.Fmtdata.
Note: If your data uses formats in more than one format catalog, you can use a
CATNAME statement to combine the required format catalogs into one. Here is
an example that combines format catalogs Work.Formats and Orion.Mailfmt into
Work.Mycat.
catname work.mycat(work.formats orion.mailfmt);
See Also
“Add Formats Referenced in a Single SAS Library to a CAS Session” on page 21