Adding Records to a KSDS

To add records to a KSDS:
  1. Include both an INFILE and a FILE statement for the data set. Specify the VSAM option in both the INFILE and the FILE statements. Specify all other options in the INFILE statement, which must precede the FILE statement.
  2. Use the PUT statement to write the record.
For a list of the options that you can use when adding records, see Special SAS Options Used with a KSDS.
When you add records to an existing KSDS, you do not have to include an INPUT statement with the associated INFILE statement. An INPUT statement is unnecessary in this case because you do not have to read a record to add a new record.
data ten;
   infile myksds vsam;
   file myksds vsam; 
   id='963215683';
   lastname='Flintstone  ';
   frstname='Pebbles     ';
   address='1234 Quarry Rd';
   city='Boulder ';
   state='CO';
   zip='12345 ';
   balance='00555';
   gpa='3.33';
   class='FR';
   hrs='13';
   finaid='Y';

   put @1  id       $9.
       @10 lastname $10.
       @20 frstname $10.
       @30 address  $15.
       @55 city     $15.
       @70 state    $2.
       @72 zip      $5.
       @77 balance  $5.
       @82 gpa      $4.
       @86 class    $2.
       @88 hrs      $2.
       @90 finaid   $1.;
run;
In the example, a record for a new student, PEBBLES FLINTSTONE, is defined and added to data set MYKSDS. The new record is added in the data set in ascending key order (in this case, according to the value of the ID variable) because output access is always direct when a new record is added to a KSDS. (See Access Types for KSDS Operations for more information.) The key for the record must be part of the PUT statement data. You must specify a unique prime key in the PUT statement data. VSAM does not allow duplicate prime keys. Keys do not have to be in ascending order during the update process.