SASMSG Function

Specifies a message from a data set. The returned message is based on the current locale and a specified key.
Category: Locale

Syntax

SASMSG (BASENAME", "KEY", <<"QUOTE"|"DQUOTE"|"NOQUOTE">
<, "substitution 1", ..., "substitution 7">>)

Required Arguments

BASENAME
the name of the data set where the message is located.
KEY
the message key.
Note: If you specify an invalid key name, then the key name is returned.
QUOTE|DQUOTE|NOQUOTE
specifies the type of quotes that are added to the message text and substitution strings.
Default:DQUOTE
substitution
string substitutions. The maximum string substitutions is 7.

Details

The SAS message data set must be a 7-bit ASCII data set. Any character that cannot be represented in the 7-bit ASCII encoding is represented in the Unicode escape format of '\uxxxx', where 'xxxx' is the base 10 numeric representation of the Unicode value of the character.
The data set used by the SASMSG function must have been created specifically for use with this function. The dataset must contain the following variables:
#
Variable Name
Type
Length
Description
1
locale
char
5
language of the message
2
key
char
60
key to identify the message
3
lineno
num
5
line # of the message in reverse order
4
text
text
1,200
text of the message
The data set must be sorted on the following variables: locale, key, and lineno. The variable lineno must be in descending order. A composite index on locale and key must be defined. Here is a sample program to sort and create an indexed data set:
%let basename=MyProduct;

proc sort data=t.&basename;
by locale key descending lineno;
run;

proc datasets lib=t 
memtype=data;
modify &basename;
index create indx=(LOCALE KEY);
run;
quit;
The returned message is based on the LOCALE system option. The LOCALE option is represented by ll_RR where ll represents the two-letter language code and RR represents the two-letter region code. If a match is not found, then the function searches for a match with the language only. If the pair locale and key are still not found, then the function defaults to the English language (en). If the key does not exist for English (en), then the key name is returned.
You can alter formatting. You can use string substitution by using the format code %s. You can change the order of substitution. In some cases, translation of a message to a language other than English might require changing the order of substitutions. You can change the order by placing an argument number specification, #nn, within a format string, where nn is the number of the argument in the substitution list. The following example demonstrates the order:
Statement
Result
msg = sasmsg
("nls.mymsg","IN_CD_LOG",
"noquote","cat","dog");
IN_CD_LOGINFO = My %#1s. Your %#2s
msg= My cat. Your dog.
IN_CD_LOGINFO = My %#2s. Your %#1s
msg= My dog. Your cat.
The SASMSG function can be used in the open code macro with the %SYSFUNC macro function.
Arguments that are passed to a function called by the %SYSFUNC macro must not be in quotes while arguments passed to the SASMSG function outside of %SYSFUNC must be quoted.
When the SASMSG function is used with the %SYSFUNC macro function the returned string is wrapped with the %NRBQUOTE function.

Examples

Example 1

The following example demonstrates the formatting feature of SASMSG:
%macro demo_sasmsg;
  data _null_;
    msg = sasmsg("nls.mymsg","IN_APW_SAVE_OK","noquote");
    put msg=;
  run;
%mend demo_sasmsg;
SAS Statements
Results
options locale = en_US;
%demo_sasmsg ;
msg=The Access Control key was successfully saved.
options locale = es_ES;
%demo_sasmsg;
msg=La clave de control de acceso se ha guardado.
options locale = french_France;
%demo_sasmsg;
msg=La clé de contrôle d'accès a bien été enregistrée.

Example 2

The following example demonstrates the open macro feature:
%MACRO PRT(loc,tb,key);
    option locale=&loc;
    %PUT %SYSFUNC(SASMSG(&tb,&key) );
%MEND PRT;
SAS Statements
Results
%PRT(en_US,&TABLEID,IN_EDIT)
"Edit"
%PRT(es_ES,&TABLEID,IN_EDIT)
"Editar"
%PRT(fr_FR,&TABLEID,IN_EDIT)
"Modifier"