Help using Base SAS procedures

how to rename filesname with #byval using newfile=bygroup

Reply
Frequent Learner
Posts: 1

how to rename filesname with #byval using newfile=bygroup

dear all,

 

I am very new to SAS programming. So please pardon me if this is an easy task.

 

I am using SAS EG 7.1, running on a linux server. I have a dataset which i need to split it into individual files by a specific dimension.

In my project, I uses ODS tagset.excelxp, with the function newfile=bygroup.

It is able to split the files into individual dimension value. However, the files name are not descriptive of whats underlying the file.

For eg., currently the files name are like test1.xml, test2.xml, test3.xml etc..

 

how can i rename this dynamically to e.g. storeA.xml, storeB.xml etc.. it will be good if the filename can reference my #byval.. my code looks someething like this:

 

ods listing close;

ods tagsets.excelxp path='<pathname>' file='Store.xml' style=analysis

options(print_header='&L'

sheet_label=' '

sheet_name='#byval1'

embedded_titles='yes'

suppress_bylines='yes'

auto_subtotals='yes'

nobyline='yes')

newfile=bygroup;

 

proc print data=work.stores label noobs split='*';

by stores;

 

title j=l font=calibri h=4 bold 'Store Sales Summary;

 

var x y z;

 

run;

ods listing;

ods tagsets.excelxp close;

 

thanks much for the help !!

Super User
Posts: 17,792

Re: how to rename filesname with #byval using newfile=bygroup

Unfortunately that's not possible with a simple option. 

 

To generate custom named files you'll need a macro. 

Super User
Posts: 6,935

Re: how to rename filesname with #byval using newfile=bygroup

If you only had to move the raw data, you could use a data step and the filevar= option in the file statement. This allows to create any wanted filename in the data step on the fly.

I even use that method when creating bunches of HTML files for the web server.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Super User
Posts: 7,401

Re: how to rename filesname with #byval using newfile=bygroup

proc sql;
  create table loop as select distinct stores from have;
quit;

data _null_;
  set loop;
  call execute(cats('ods tagsets.excelxp file="c:\',stores,'";'));
  call execute(cats('proc print data=have nowd; where stores="',stores,'"; run;'));
  call execute('ods tagsets.excelxp close;');
run;
Ask a Question
Discussion stats
  • 3 replies
  • 287 views
  • 0 likes
  • 4 in conversation