BookmarkSubscribeRSS Feed
abraham1
Obsidian | Level 7

Hi,

The below code is working when I export all datasets into multiple excel file in a specified location but If I want to save all the output in a single excel file with multi-sheet output, where should I change the program. I tried all possible way but its not working.

%macro SASToExcel(ExportLibrary=);
%* obtain list of datasets in the library;
    ods output members = _Members;
    proc datasets lib = &ExportLibrary; run; quit;
    proc sql;
*get the name of datasets into the list using Dataset1, Dataset2 etc;
        select Name into :Dataset1-
from _Members;
    quit;
*store the number of records to control the loop;
%let NumOfDatasets=&sqlobs;
%*loop to export all your data sets;
    %do index = 1 %to &NumOfDatasets;
		proc export data=&ExportLibrary..&&Dataset&index.
        outfile="/GST/COUNCIL/COUNTRY/Program/&&dataset&index..xlsx"
        dbms=XLS replace;
        run;
    %end;
%mend;
%SASToExcel(ExportLibrary=work);
5 REPLIES 5
abraham1
Obsidian | Level 7
Thank you for the suggestion. As the variable label is more than 50 characters, I am getting warning message as truncation happening during exporting like below. I just wanted to learn how macro work as a newbie. Thanks once again

NOTE: The variable label Employee information in Columbia state of America has been truncated to Employee information
Tom
Super User Tom
Super User

@abraham1 wrote:
Thank you for the suggestion. As the variable label is more than 50 characters, I am getting warning message as truncation happening during exporting like below. I just wanted to learn how macro work as a newbie. Thanks once again

NOTE: The variable label Employee information in Columbia state of America has been truncated to Employee information

Not clear why it gives that message. An XLSX file does not have any concept of a variable label.

ballardw
Super User

It might help to include the code along with all the notes, warnings and/or errors generated.

 

Copy the entire procedure step with all the notes from the log and then paste into a code box on the forum opened with the </> icon to preserve formatting of text and any diagnostic characters.

Reeza
Super User
And you really shouldn't be using XLS files anymore. If you need any more reasons for switching off, here's one example.
https://www.bbc.com/news/technology-54423988

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 2181 views
  • 5 likes
  • 5 in conversation