export multiple excel by a variable

Hi All, i have a statistical df organised by years, for example 5 and i'll would like to export my table in 5 different Excel Workbook, how can i do? First i used SAS and i did it with macros like this
%let elenco = gen feb mar apr giu;
%macro export;
%local i;
%let i = 0;
%do %until (%scan(&elenco,&i+1) = );
%let i = %eval(&i+1);
%let ele=%scan(&elenco,&i);
data month_&i;
set tot;
where month="&ele";
run;
proc export data = month_&i
outfile = "C:\prova_&i.xls"
dbms = excelcs replace;
sheet="month_&i";
run;
%end;
Thanks in advance
Elisa

Not too familiar with sas, and fair warning, this forum is probably not the ideal place to help with sas code. For help there, check out https://communities.sas.com/

In R, a popular package to help you import Excel files is the readxl package.

Their docs recommend the following packages to help with exporting,

Writing Excel files : The example files datasets.xlsx and datasets.xls (Examples were discussed here https://readxl.tidyverse.org/) were created with the help of openxlsx (and Excel). openxlsx provides “a high level interface to writing, styling and editing worksheets”.

l <- list(iris = iris, mtcars = mtcars, chickwts = chickwts, quakes = quakes)
openxlsx::write.xlsx(l, file = "inst/extdata/datasets.xlsx")

writexl is a new option in this space.... It’s a portable and lightweight way to export a data frame to xlsx, based on libxlsxwriter. It is much more minimalistic than openxlsx, but on simple examples, appears to be about twice as fast and to write smaller files.

All those packages have nice docs. If you're having trouble, I'd suggest a follow-up topic with a reprex to show folks exactly where you're having trouble.

Thank you.
I know that is R community, my problem was translate a SAS script in a R script, because i worked 15 years with SAS software and now i must use R.

I find the solution with group_split() and write_xlsx.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.