BookmarkSubscribeRSS Feed
hdg
Obsidian | Level 7 hdg
Obsidian | Level 7

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

6 REPLIES 6
LinusH
Tourmaline | Level 20

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
Barnipaz
Obsidian | Level 7

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.

hdg
Obsidian | Level 7 hdg
Obsidian | Level 7

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

LinusH
Tourmaline | Level 20

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
hdg
Obsidian | Level 7 hdg
Obsidian | Level 7

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)

ballardw
Super User

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 966 views
  • 0 likes
  • 4 in conversation