|SAS/ACCESS Interface to IMS-DL/I Software|
When a DATA step program uses qualified calls, you designate variables containing the SSAs with the SSA= option in the DL/I INFILE statement. The values of SSA variables do not have to be constants. They can be built by the program using SAS assignment statements, functions, and operators. You can construct SSAs conditionally and change SSA variable values between calls.
|The Concatenation Operator|
One of the techniques for building an SSA is to incorporate the value of another variable in the SSA variable's value. This can be accomplished with the concatenation operator (||), as in this example:
This statement assigns a value to SSA1 that consists of the literal CUSTOMER(SSNUMBER =, the current value of the variable SSN, and the right parenthesis. If the current value of SSN is 303-46-4887, the SSA is
Note: The concatenation operator acts on character values. If you use a numeric
variable or value with the concatenation operator, the numeric value is converted
automatically to character using the BEST12. format. If the value is less
than 12 bytes, it is padded with blanks and, if longer than 12 bytes, it could
lose precision when converted. If you want to insert a numeric value via concatenation,
you should explicitly convert the value to character with the PUT function
(described in the next section).
|The PUT Function|
SSA variables in a DATA step program must be character variables. However, you may sometimes need to qualify an SSA with a numeric value. To insert a numeric value in an SSA character variable, you can use the SAS PUT function.(footnote 1) For more information on the PUT statement, see SAS Language Reference: Dictionary.
The PUT function's form is
the result of the PUT function is a character string assigned to the variable NEWDATE, a character variable. The result is a character value even though DATEVALU and the DATE7. format are numeric. If DATEVALU=38096, the value of NEWDATE is:
Using the PUT function, you can translate numeric values for use in SSAs. For example, to select WIRETRAN segments with WIREAMMT values less than $500.00, you could construct an SSA like this:
maxamt=500; ssa1='WIRETRAN(WIREAMMT <'||put(maxamt,pd5.2)||')';
First, you assign the numeric value to be used as the search criterion to a numeric variable. In this case, the value 500 is assigned to the numeric variable MAXAMT. Then you construct the qualified SSA using concatenation and the PUT function. The PUT function's result is a character string consisting of the value of MAXAMT in PD5.2 format.
Consider a more complicated example using the ACCTDBD database. In this case, you want to select all checking accounts for which the last statement was issued a month ago today or more than 31 days ago.
The following SAS statements illustrate one approach to constructing an SSA to select the appropriate accounts. The numbered comments after this example correspond to the numbered statements:
data _null_;  tday = today();  d = day(tday); m = month(tday); y = year(tday);  if d = 31 then if m = 5 or m = 7 or m = 10 or m = 12 then d = 30;  if m = 3 then if d < 28 then d = 28; if m = 1 then do; m = 12; y = y - 1; end; else m = m - 1;  datpmon = mdy(m,d,y);  datem31 = tday - 31;  ssa1 = 'CHCKACCT (STMTDATE= ' || put(datpmon,mmddyy6.) || '| STMTDATE> ' || put(datem31,mmddyy6.) || ')'; stop; run;
|Use the SAS function TODAY to produce the current date as a SAS date value and assign it to the variable TDAY.|
|Use the SAS functions DAY, MONTH, and YEAR to extract the corresponding parts of the current date and assign them to appropriate variables.|
|Modify D values to adjust when previous month has fewer than 31 days.|
|Modify the month variable (M) to contain the prior month value.|
|Assign the SAS date value for last month, the same day as today, to the variable DATPMON.|
|Subtract 31 from the SAS date representing today's date and assign the value to the variable DATEM31.|
|To build the SSA, concatenate these elements:
If these statements are executed on 28 March 1995, the value of SSA1 is
CHCKACCT(STMTDATE =02/28/95|STMTDATE >02/28/95)
|Setting SSAs Conditionally|
Using SAS IF-THEN/ELSE statements, SSA variables can be assigned values conditionally. Consider Example 2 in which the ACCTDBD database is updated with transaction information stored in a standard sequential file with fileref TRANIN. Each TRANIN record contains data for one deposit or withdrawal transaction for a checking or savings account. The program uses the TRANIN records to construct new CHCKDEBT, CHCKCRDT, SAVEDEBT, or SAVECRDT segments and then inserts the new segment in the ACCTDBD database. Notice that the concatenation operator (||) is used to incorporate the value of the ACCT_NUM variable in the SSA.
The program first reads a record from the TRANIN file and then determines whether the data are for a checking or a savings account by evaluating the value of the variable ACCTTYPE. If ACCTTYPE='C', the program constructs a qualified SSA for a CHCKACCT segment. Next, the program determines whether the record represents a debit or credit transaction and builds an unqualified SSA for a CHCKDEBT or CHCKCRDT segment, as appropriate.
If ACCTTYPE='S', a qualified SSA for a SAVEACCT segment is built, and then an unqualified SSA for a SAVEDEBT or SAVECRDT segment is set up.
|Changing SSA Variable Values between Calls|
A DATA step program can issue multiple calls within a DATA step execution, and the value of an SSA variable can be changed between each call. An example of this is the following code, which is used in Example 4: Issuing REPL Calls in Introducing the IMS-DL/I DATA Step Interface:
data _null_; set ver6.newaddr; length ssa1 $31; infile acctsam dli ssa=ssa1 call=func status=st pcbno=4; ssa1 = 'CUSTOMER(SSN =' || ssn || ')'; func = 'GHU '; input; if st = ' ' then do; func = 'REPL'; ssa1 = ' '; file acctsam dli; put _infile_ @; put @52 newaddr1 $char30. @82 newaddr2 $char30. @112 newcity $char28. @140 newstate $char2. @162 newzip $char10.; if st ¬= ' ' then link abendit; end; else if st = 'GE' then do; _error_ = 0; stop; end; else link abendit; return; abendit: file log; put _all_; abort; run;
These statements are part of a program that updates CUSTOMER segments in the ACCTDBD database with information from the SAS data set VER6.NEWADDR. CUSTOMER segments are retrieved using GHU calls with a qualified SSA, SSA1. Once a segment is retrieved, the data from the SAS data set are overlaid on the old values of the segment and a REPL call is issued. Since a REPL call acts on a segment retrieved previously, no SSA is needed. Therefore, the value of the SSA1 variable is changed to blanks before the REPL call is issued.
Top of Page
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.