Append or update?

SAS can generate many types of output: plain text, XML, PDF, RTF, Excel, etc. With all of these and the SAS procedures like PROC REPORT, PROC TABULATE and so on, it might seem surprising for me to say that I have been generating output with data step PUT and FILE statements. There was, of course, a reason for this: creating text files for loading into a new database-driven software application. At one stage, I also did some data interleaving at the output stage and that’s when I discovered that the default behaviour for SAS FILE statements is to completely overwrite a file unless the MOD option was specified. Adding that switches on APPEND behaviour. The code below adds a header in one step while adding data below it in another. I know that there are slicker ways to achieve this like setting up your data as you want it or using _N_ to ensure that something only appears once but here’s another way. As per the Perl, there’s often more than one way to do something with SAS.

DATA _NULL_;
 FILE DS_DATA;
 PUT "FIELDTYPE;DATASETNAME;DATASETLABEL;DATASETLAYOUT;DATASETCLASS;DATASETSTANDARDVERSION";
RUN;

DATA _NULL_;
 SET DS_ISPEC;
 FILE DS_DATA MOD;
 LINE="DATASETSTANDARD;"||TRIM(MEMNAME)||";"||TRIM(MEMLABEL)||";;;"||TRIM(MEMVER);
 PUT LINE;
RUN;

Leave a Reply