Help using Base SAS procedures

Export proc univariate output to multiple microsoft excel sheets

Accepted Solution Solved
Reply
Contributor
Posts: 39
Accepted Solution

Export proc univariate output to multiple microsoft excel sheets

Okay, so I am trying to get the results of proc univariate to export to a microsoft excel sheet. I need multiple ones. Currently, my code is:

 

%macro test2;
        %do i = 1 %to 13;
            %let v = %scan(&varsX,&i.);
            ods html file="testfile.cls";
            proc univariate data=test;
                var &v;
            run;
            ods html close;
        %end;
    %mend test;
    %test2;

 

where my variables are defined in a list above. This prints out a bunch of sheets saved as ASCII files, but I want them all as excel sheets in the same workbook.

 


Accepted Solutions
Solution
‎09-25-2015 06:23 AM
Super User
Posts: 10,497

Re: Export proc univariate output to multiple microsoft excel sheets

Not tested but some thing like this should get you started:

 

%macro test3;

      ods tagsets.excelxp file="testfile.xlm" options (sheet_interval='PROC');
        %do i = 1 %to 13;
            %let v = %scan(&varsX,&i.);
           
            proc univariate data=test;
                var &v;
            run;
           
        %end;

    ods tagsets.excelxp close;
    %mend test3;
    %test3;

 

The XML file generated can be opended in Excel.

View solution in original post


All Replies
Solution
‎09-25-2015 06:23 AM
Super User
Posts: 10,497

Re: Export proc univariate output to multiple microsoft excel sheets

Not tested but some thing like this should get you started:

 

%macro test3;

      ods tagsets.excelxp file="testfile.xlm" options (sheet_interval='PROC');
        %do i = 1 %to 13;
            %let v = %scan(&varsX,&i.);
           
            proc univariate data=test;
                var &v;
            run;
           
        %end;

    ods tagsets.excelxp close;
    %mend test3;
    %test3;

 

The XML file generated can be opended in Excel.

Contributor
Posts: 39

Re: Export proc univariate output to multiple microsoft excel sheets

Great, this puts them all in the same file with sheets which is awesome.

 

You have any idea how to keep a title in there because when I run this version of code it drops the titles.

Super User
Posts: 17,818

Re: Export proc univariate output to multiple microsoft excel sheets

Look at the header/footer, the title should be in there. You can embed the title/footer by looking at the ODS TAGSETS.EXCELXP option - specifically embedded_titles and embedded_footnotes.

See the reference and options available here:
http://support.sas.com/rnd/base/ods/odsmarkup/excelxp_help.html
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 406 views
  • 1 like
  • 3 in conversation