Search code examples
sassas-ods

How can I create SAS html files with names corresponding to a dataset field


I'm trying to create a file for each record in my SAS dataset. I have been able to succesfully do this using SAS ODS output by using the "newfile=page" option and then simply running a proc report on the dataset. The problem I'm having is that this results in gerneric, sequentially numbered file names (test, test1, test2, etc...). I'd like to name each file based on a variable in the dataset. In the example below, I'd like the file names to be titled based on the "seq_nbr" in the dataset.

    ods html path = "C:\test\"
    file = 'test.html'
    contents = 'contents.html
    frame = 'frame.html'
    code = (url="C:\test\javascript.js")
    newfile=page;

    proc report data = test2 nowindows headline headskip;
    column tDate tTime created_by cmtText;
    by seq_nbr;

    run;

Solution

  • You need a macro for this

    %macro doit;
    proc sql;
    select count(*) into :n from test2 ;
    quit;
    
    %do i=1 %to &n;
    data _null_;
    if _n_=&i call symput('name',seq_nbr);
    run;
    
    proc export data=something outfile="&name";
    run;
    %end;
    
    %mend;
    %doit;