BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
WesBarris
Obsidian | Level 7

I'm trying to write some SAS code that will read in a .xlsx file if it exists, otherwise I would like it to create an empty dataset.  I've written some code but it hangs at the "call execute" line.  Here is what I am trying:

data _null_;

   if fileexist("c:\test.xlsx") then

      call execute('proc import datafile="c:\test.xlsx" out=work.lixi dbms=excelcs replace;');

   else

      call execute('data lixi;infile datalines;input wingband;datalines;;');

run;

What am I doing wrong?  Is there a better way to do this?

1 ACCEPTED SOLUTION

Accepted Solutions
ArtC
Rhodochrosite | Level 12

Add a RUN; statement to each of your CALL EXECUTE steps. 

The second CALL EXECUTE could be simplified.

data _null_;

   if fileexist("c:\test.xlsx") then

      call execute('proc import datafile="c:\test.xlsx" out=work.lixi dbms=excelcs replace;run;');

   else

      call execute('data lixi;stop;wingband=.;run;');

run;

View solution in original post

7 REPLIES 7
ArtC
Rhodochrosite | Level 12

Add a RUN; statement to each of your CALL EXECUTE steps. 

The second CALL EXECUTE could be simplified.

data _null_;

   if fileexist("c:\test.xlsx") then

      call execute('proc import datafile="c:\test.xlsx" out=work.lixi dbms=excelcs replace;run;');

   else

      call execute('data lixi;stop;wingband=.;run;');

run;

WesBarris
Obsidian | Level 7

Thanks Art.  However, it SAS still hangs at the first call execute statement.  Here is what I have:

data _null_;

   if fileexist("c:\test.xlsx") then

      call execute('proc import datafile="c:\test.xlsx" out=work.lixi dbms=excelcs replace;run;');

   else

      call execute('data lixi;stop;wingband=.;run;');

run;

ArtC
Rhodochrosite | Level 12

Try changing the DBMS to DMBS=EXCEL rather than EXCELCS.

WesBarris
Obsidian | Level 7

Hi Art,

When I change DBMS=EXCELCS to DBMS=EXCEL, I get this error in the log:

ERROR: DBMS type EXCEL not valid for import.

When I was trying to get this to work by trial-and-error I stumbled across

DBMS=EXCELCS.  It was the only DBMS that worked for me.

ArtC
Rhodochrosite | Level 12

I have not used EXCELCS, but I did find this SAS note.  Not the same but it might be related.  Under some versions of SAS .XLSX can be a problem while .XLS is not.

http://support.sas.com/kb/37/479.html

Tom
Super User Tom
Super User

Just run the import without the rest.  Does it still hang?

If not then try writing the code to a file instead.

filename code temp;

data _null_;

   file code;

   if fileexist("c:\test.xlsx") then

      put 'proc import datafile="c:\test.xlsx" out=work.lixi dbms=excelcs replace;run;' ;

   else

      put 'data lixi;stop;wingband=.;run;';

run;

%inc code / source2 ;

WesBarris
Obsidian | Level 7

Yes, it still hung.  I ended up copying that file and pasting as a new file and the SAS code worked.

Thanks for your help.

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 7 replies
  • 7580 views
  • 0 likes
  • 3 in conversation