Adding Records to a Data Set

The %CSTUTILAPPENDMETADATARECORDS macro adds new records to a data set. This macro requires an input data set that contains the records to use to update the target data set. It takes records from the input data set and either appends or merges the records to the target data set.
Note: Appending records to a data set always adds rows to the target data set even if the rows already exist in the target data set. Merging records adds new rows and updates existing rows. If keys are present, the target data set is sorted and duplicate key records are deleted.
In this example, the newstudy.source_values data set is merged (indicated by _cstUpdateDSType=merge) with the work.newrecs data set. The _cstOverwriteDup parameter enables duplicate records from work.newrecs to overwrite those records in newstudy.source_values.
 *****************************
*  Merge in the dummy data  *
*****************************;
%cstutilappendmetadatarecords(
        _cstStd=CDISC-SDTM,
        _cstStdVer=3.1.3,
        _cstDS=newstudy.source_values,
        _cstNewDS=work.newrecs,
        _cstUpdateDSType=merge,
        _cstOverwriteDup=y,
        _cstTestMode=n);
Note: To merge successfully, the keys for the data sets must match. Any discrepancies in the keys are reported either to the SAS log file or to the Results data set.
Before running the macro, the work.newrecs data set was created for the _cstNewDS macro parameter.
Note: The data set (newstudy.source_values) must share the same structure as the target data set (work.newrecs).
The following display shows an example of the work.newrecs data set:
Example work.newrecs Data Set
example work.newrecs data set
After the macro is run, the newstudy.source_values data set is updated with the new EG record and the IE record. The following display shows an example of the updated data set:
Example of Updated Data Set
updated example data set
The row count (Rows) is increased from 28 to 30 (compare to the image ), which indicates that the two records were added from the work.newrecs data set.
The following display shows the updated properties of the newstudy.source_values data set:
Updated Properties of the newstudy.source_values Data Set
updated properties of the newstudy.source_values data set
The results of running the macro write to the work._cstresults data set because the data set was created by the macro in the previous example.
The following display shows part of the work._cstresults data set, in which row 5 contains the message generated after running the %CSTUTILAPPENDMETADATARECORD macro:
Message Generated After Running the %CSTUTILAPPENDMETADATARECORD Macro
row 5 contains the message generated after running the %CSTUTILAPPENDMETADATARECORD macro
Note: Not all columns or rows are shown.
The following display shows part of the transaction log data set, which shows that it was updated for each row of data added (rows 2 and 3):
Transaction Log Data Set
transaction log data set
Note: Not all columns or rows are shown.
In this example, the newstudy.source_values data set is appended (indicated by _cstUpdateDSType=append) to the work.newrecs data set. When appending rows, the _cstOverwriteDup parameter is ignored.
***************************
*  Append the dummy data  *
***************************;

%cstutilappendmetadatarecords(
        _cstStd=CDISC-SDTM,
        _cstStdVer=3.1.3,
        _cstDS=newstudy.source_values,
        _cstNewDS=work.newrecs,
        _cstUpdateDSType=append,
        _cstOverwriteDup=y,
        _cstTestMode=n);