Help using Base SAS procedures

exporting in SAS

Reply
Frequent Contributor
Frequent Contributor
Posts: 79

exporting in SAS

Hello, I have a set of datasets which I would like to output in an Excel File. Is there a way to do this quickly rather than calling proc export each time for each dataset

%let MyDS = ('out.Ids', 'out.Vars', 'out.Places')

%let MyDSname = (Ids, Vars, Places)

I would like to create a macro that check if each dataset exists and then output to an Excel spreadsheet with the Tab name as specified in the corresponding MyDSname ...

Something like... %macro Out(MySpreadsheetName, MyDS, MyDSname);

Thanks very much for your help

Super User
Posts: 5,430

Re: exporting in SAS

Shouldn't be a problem.

Use open() function to check the existence of a data set, then conditionally execute a Proc Export.

Data never sleeps
Contributor
Posts: 33

Re: exporting in SAS

Or the exist function to check the the existence.

%sysfunc(exist(<data_set>));

If you use the open(), as suggested by LinusH, it's better to use the close after the check, otherwise the DataSet could be locked.

Frequent Contributor
Frequent Contributor
Posts: 79

Re: exporting in SAS

Thank you both. but I am also looking how to Parse my macro variables so as to use the proc Export command I'm not sure how to use the loop

Super User
Posts: 5,430

Re: exporting in SAS

You just use the macro variables in the code. Perhaps you need to learn a little about macro programming before getting started with this task.

Loop, what loop?

Data never sleeps
Frequent Contributor
Frequent Contributor
Posts: 79

Re: exporting in SAS

Thanks Linus, but the macro variable MyDS refers to the list of datasets 3 in this case. The macro variable MyDSname corresponds to the name I want to call the tab in the spreadsheet which they are store.

I dont think I can just use a proc export directly passing MyDS and MyDSname

I would have to parse MyDS to extract the first value same way MyDSname and then use proc export.

. I wanst sure how to do this.

%let MyDS = ('out.Ids', 'out.Vars', 'out.Places') %let MyDSname = (Ids, Vars, Places)

Super User
Posts: 11,343

Re: exporting in SAS

Effective macro coding always starts with the same place: A base SAS section of code that works.

Provide an example of ONE of the proc exports you are attempting that works and then indicate which pieces change.

And you almost never need to include quotes in the parameters as they will be treated by the macro processor as text.

Ask a Question
Discussion stats
  • 6 replies
  • 277 views
  • 0 likes
  • 4 in conversation