BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Reeza
Super User

It isn't complex, but you seem to want someone else to do the work rather than modify posted code.

People have asked you to repost the code you used and claim does not work and you have not, so why should anyone invest anymore time in a question that works for everyone else?

NKormanik
Barite | Level 11

Because I don't know how to do it.  I'm the one asking how.

At this point I'd like a clear path for others out there that search for the answer.

Reeza
Super User

Do you want code or instructions on how to solve the problem?

Patrick
Opal | Level 21

You've updated/changed your initial post changing the table names. Originally they were something like "_1234" and you wanted the excel to be named "1234.xls".

Is my assumption correct that you don't know how to write SAS code? As the change to the code already posted is really simple.

NKormanik
Barite | Level 11

Yes, , your assumption is correct.  I've looked over your code and can't see any easy way of solving the truncation issue.  So..., how is it done?

Tom
Super User Tom
Super User

So the ORIGINAL solution should do what you want, with trivial changes.

Here is a summary of the changes I made.

1) Eliminate the selection criteria used to identify which SAS datasets to export to SAS.  Instead it will export them all.

2) Eliminate the SUBSTR() function call that was removing the first letter of the database name.

3) Added macro variables OUTPATH and INPATH to have an explicit location to set the source and the target directory names for reading the SAS datasets and writing the EXCEL files.  If you want them in the same directory you could eliminate one of the macro variables or just set them both to the same value.

4) Added an explicit LIBNAME statement.  Note that the libref used (SOURCE) has to match the value used in the WHERE clause to select the list of tables to export.

5) Added %NRSTR() into the string passed to CALL EXECUTE to avoid possible timing issues caused by pushing macro calls onto the execute stack.

%macro export(inlib,intbl,outpath,outfile);
  proc export data=&inlib..&intbl 
    outfile= "&outpath\&outfile..xls"      
    dbms=xls label replace;
    putnames=yes;
  run;
%mend;


%let outpath=c:\excel_files;

%let inpath=c:\sas_files;

libname source "&inpath";

data _null_;

  set sashelp.vstable (where=(libname='SOURCE'));

  call execute(cats('%nrstr(%export)('

                   ,catx(',',libname,memname,'&outpath',memname)

                   ,')'));
run;

NKormanik
Barite | Level 11

Outstanding.  Thank you!

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
  • 21 replies
  • 17503 views
  • 3 likes
  • 5 in conversation