%VALIDCHS Macro Function
Validates the character(s) encoding compatibility for data set variables.
| Restriction: | This macro should not be used when the encoding value equals DEFAULT. |
|---|
Table of Contents
- Syntax
- Required Argument
- Optional Arguments
- Details
- Basics
- Automatic Macro Variable
- Examples
- Example 1: Simple Validation of the Character Data in the Data Set
- Example 2: Validate the Character Data in theData Set in the Specified Encoding
- Example 3: Validate the Character Data and Check the Compatibility
- Example 4: Validate the Character Data and Check the Compatibility
Syntax
Required Argument
dsnm=<libref.>dataset_name
name of the data set to be verified.
Optional Arguments
ENCODING=encoding_name
optional encoding name that the %VALIDCHS macro function uses to validate that the characters in the data set are valid for the specified encoding. If the ENCODING= option is not specified, the encoding of the data set is used.
libnm=libref_name
name of the SAS library to be verified.
COMPATIBLE=encoding_name
optional encoding that the %VALIDCHS macro function uses to verify the compatibility of the data in the data set with the specified encoding. It helps determine whether you can successfully transfer the data set between a server and a client where the encoding is different. Incompatible characters can cause data transfer issues.
Details
Basics
The %VALIDCHS macro function scans the data set and
inspects the characters in the data set’s character variables to determine whether
they
are valid for the specified encoding. If an ENCODING= option is specified, the %VALIDCHS
macro function validates based on the ENCODING= value. If the ENCODING= option is
not
specified, then %VALIDCHS uses the encoding of the data set. If the COMPATIBLE= option
is specified, %VALIDCHS validates the contents of the character data in the encoding
of
the data set (or the encoding of the ENCODING= option). Then it verifies the
compatibility based on the encoding that is specified by the COMPATIBLE= option. For
example, a data set with a euc-cn encoding, Chinese characters, and
COMPATIBLE=wlatin1 is specified. %VALIDCHS verifies that the
characters are valid for the euc-cn encoding. Then %VALIDCHS verifies the compatibility
of the characters to see whether they are supported by the wlatin1 encoding. If
%VALIDCHS detects invalid character(s) in the data set, it displays a message and
continues validation.
Automatic Macro Variable
_validchars_rc is an automatic macro variable that is generated by %VALIDCHS. It indicates the test status. Here is an example:
2: No invalid characters are found but data will cause the truncation
1: No invalid characters are found
0: Invalid characters are found
-1: Invalid characters are found and also data will cause the truncation
-2: General error
Examples
Example 1: Simple Validation of the Character Data in the Data Set
%VALIDCHS uses the encoding of the input data set.
%VALIDCHS(dsnm=sashelp.class);
%put &_validchars_rc;
The encoding of the data set is us-ascii. The %VALIDCHS macro function finds that all the character data is valid in us-ascii so that it returns following message in the log:
NOTE: All characters in the dataset: sashelp.class (encoding:us-ascii) are valid. 0
Example 2: Validate the Character Data in theData Set in the Specified Encoding
%VALIDCHS uses the specified encoding to validate these characters:
%VALIDCHS(dsnm=sashelp.class, encoding=utf-8);
%put &_validchars_rc;
These messages are written to the SAS log:
NOTE: All characters in the dataset: sashelp.class (encoding:utf-8) are valid. 0
Example 3: Validate the Character Data and Check the Compatibility
%VALIDCHS(dsnm=sashelp.class, encoding=euc-cn, compatible=wlatin1);
%put &_validchars_rc;
These messages are written to the SAS log:
NOTE: All characters in the dataset: sashelp.class (encoding:euc-cn) are compatible to wlatin1 encoding. 0
Example 4: Validate the Character Data and Check the Compatibility
The following data set has the wlatin1 encoding and a national character:
data mydata;
length ch $1.;
ch = ‘€’;
run;
%VALIDCHS(dsnm=mydata, encoding=wlatin1, compatible=utf-8);
%put &_validchars_rc;
These messages are written to the SAS log:
WARNING: Found possible truncation in the variable: ch at observation number: 1 ERROR: Detected the issue in the dataset: mydata (encoding:wlatin1) when validating the compatibility to ::utf-8 encoding. 2