space
Previous Page | Next Page

Advanced Topics for the IMS DATA Step Interface

SSAs in IMS DATA Step Programs


Using the SSA= Option

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:

ssa1='CUSTOMER(SSNUMBER ='||ssn||')';

This statement assigns a value to SSA1 that consists of the literal CUSTOMER(SSNUMBER =, the current value of the variable SSN, and the close parenthesis. If the current value of SSN is 303-46-4887, the SSA is

CUSTOMER(SSNUMBER =303-46-4887)

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 convert the value to character with the PUT function (described in the next section).  [cautionend]


The PUT Function

SSA variables in a DATA step program must be character variables. However, you might 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 about the PUT statement, see SAS Language Reference: Dictionary.

The PUT function's form is as follows:

PUT(argument1, format)
Argument1 is a variable name or a constant, and format is a valid SAS format of the same type (numeric or character) as argument1. The PUT function writes a character string that consists of the value of argument1 output in the specified format. The result of the PUT function is always a character value, regardless of the type of the function's arguments. For example, in the following statement the result of the PUT function is a character string assigned to the variable NEWDATE, a character variable.
newdate=put(datevalu,date7.);

The result is a character value even though DATEVALU and the DATE7. format are numeric. If DATEVALU=38096, the value of NEWDATE is:

newdate='20APR64'

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_;
1    tday = today();
2    d = day(tday);
   m = month(tday);
   y = year(tday);

3    if d = 31 then
      if m = 5 or
         m = 7 or
         m = 10 or
         m = 12 then
         d = 30;
4    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;

5    datpmon = mdy(m,d,y);
6    datem31 = tday - 31;

7    ssa1 = 'CHCKACCT
       (STMTDATE= ' || put(datpmon,mmddyy6.) ||
       '| STMTDATE> ' || put(datem31,mmddyy6.) || ')';
   stop;
run;

[1]

Use the SAS function TODAY to produce the current date as a SAS date value and assign it to the variable TDAY.

[2]

Use the SAS functions DAY, MONTH, and YEAR to extract the corresponding parts of the current date and assign them to appropriate variables.

[3]

Modify D values to adjust when previous month has fewer than 31 days.

[4]

Modify the month variable (M) to contain the prior month value.

[5]

Assign the SAS date value for last month, the same day as today, to the variable DATPMON.

[6]

Subtract 31 from the SAS date representing today's date and assign the value to the variable DATEM31.

[7]

To build the SSA, concatenate these elements:

  • a literal that is composed of the segment name (CHCKACCT), a open parenthesis, search field name (STMTDATE), and the relational operator =.

  • a character string consisting of the value of DATPMON output in the MMDDYY6. format. The character string is the result of the PUT function.

  • a literal consisting of the Boolean operator | (or), the search field name (STMTDATE), and the relational operator >.

  • a character string consisting of the value of DATEM31 output in the MMDDYY6. format. The character string is the result of the PUT function.

  • a literal consisting of a close parenthesis.

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: Incorrectly Updating a Database without Recovery Logic 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 is 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 How to Use the IMS 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 is 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.


FOOTNOTE 1:   The PUT function can also be used to format a character value with any valid character format. [arrow]

space
Previous Page | Next Page | Top of Page