2

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;
Joe
  • 62,789
  • 6
  • 49
  • 67
rascale
  • 79
  • 1
  • 6
  • 1
    I don't think there's a "simple" solution to this. I think your options are either to do something like the top answer to [this question](http://stackoverflow.com/questions/9485769/sas-proc-sgplot-by-group-auto-file-names) suggests, which is to make a macro that iterates for each of your by values (thus giving you a macro variable to use for the title), or possibly to use `PROC DOCUMENT` - but that I think would be extremely complicated. Or, alternately, to use the data step to write the HTML file out (as if it were a text file); possible with a relatively simple file. – Joe Jul 16 '15 at 21:24
  • If one of those methods works for you, I could probably help show it, though the `PROC DOCUMENT` method is probably more complicated than I have time to show. – Joe Jul 16 '15 at 21:25
  • The simplest way may be to simply rename the files afterwards. – Robert Penridge Jul 16 '15 at 21:28
  • Thanks! Following the option of creating a macro to iterate each record worked for me. – rascale Jul 16 '15 at 22:15
  • 2
    @rascale Would you mind posting the solution you ended up using, and then marking it as accepted so that others may benefit from it? Thanks. – Robert Penridge Jul 21 '15 at 16:20

1 Answers1

0

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;
Dirk N
  • 717
  • 3
  • 9
  • 23