Saturday, March 5, 2011

How to write out a SAS data file and corresponding underline codes?


In SAS you can use  proc export  to write out data files with different delimiters.

/* Data are delimitered by space */
proc export data=sasuser.credit outfile='c:\sasdata\credit' dbms=dlm;
      delimiter=' ';
run;

/* Data are delimitered by "," */
proc export data=sasuser.credit outfile='c:\sasdata\credit' dbms=dlm;
      delimiter=',';
run;

The corresponding underline codes in SAS logfile:
9336   /**********************************************************************
9337   *   PRODUCT:   SAS
9338   *   VERSION:   9.2
9339   *   CREATOR:   External File Interface
9340   *   DATE:      04MAR11
9341   *   DESC:      Generated SAS Datastep Code
9342   *   TEMPLATE SOURCE:  (None Specified.)
9343   ***********************************************************************/
9344      data _null_;
9345      %let _EFIERR_ = 0; /* set the ERROR detection macro variable */
9346      %let _EFIREC_ = 0;     /* clear export record count macro variable */
9347      file 'c:\sasdata\credit' delimiter=',' DSD DROPOVER lrecl=32767;
9348      if _n_ = 1 then        /* write column names or labels */
9349       do;
9350         put
9351            "Account"
9352         ','
9353            "Name"
9354         ','
9355            "Type"
9356         ','
9357            "Transaction"
9358         ;
9359       end;
9360     set  SASUSER.CREDIT   end=EFIEOD;
9361         format Account $4. ;
9362         format Name $17. ;
9363         format Type $1. ;
9364         format Transaction $6. ;
9365       do;
9366         EFIOUT + 1;
9367         put Account $ @;
9368         put Name $ @;
9369         put Type $ @;
9370         put Transaction $ ;
9371         ;
9372       end;
9373      if _ERROR_ then call symputx('_EFIERR_',1);  /* set ERROR detection macro variable */
9374      if EFIEOD then call symputx('_EFIREC_',EFIOUT);
9375      run;

No comments:

Post a Comment