Express “PUT all variables” in a data step to export SAS data

前端 未结 4 1282
星月不相逢
星月不相逢 2021-01-20 18:52

Goal: export an entire SAS dataset to a tab-delimited text file using a data step.

Problem: In every example that I can find, such as this one, one must specify ev

4条回答
  •  别那么骄傲
    2021-01-20 19:13

    You need to use both a variable list and format list to use the _ALL_ keyword in the PUT statement and not have it generate the names. The format list does not need to contain any actual formats but it cannot be empty. So this code will create a CSV file, without column headers.

    data _null_;
      file 'want.csv' dsd ;
      set have ;
      put (_all_) (+0) ;
    run;
    

    If you do want column headers there are a couple of methods you could use. Here is one that uses PROC TRANSPOSE to generate a dataset with the variable names. This can be used to write the header row and then the above code can be used with just the addition of the MOD keyword to the FILE statement to append the data records.

    proc transpose data=have(obs=0) out=names ;
      var _all_;
    run;
    data _null_;
      file 'want.csv' dsd ;
      set names end=eof;
      put _name_ @ ;
      if eof then put;
    run;
    

提交回复
热议问题