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

I have been trying for over a week to figure out how to import non-SAS data (.dta is my main interest, but also .csv).   I have looked at numerous examples using LIBNAME and PROC IMPORT and only receive errors-most of them saying that the file I am pointing to does not exist--which it does). 


I am writing the syntax in the correct order and following the rules of the language as provided in the examples (e.g. UCLA's SAS Starter Kit, My Little SAS Book, SAS Help Forum).  And yet, I have no ability to actually import data regardless of the extension.  I am an expert user of STATA, so I am confident that my ability to follow the logic provided in syntax examples is not flawed (and I will hold off on rambling about the superior intuitiveness of Stata's help files/programming language).

In any event, does anyone know if this is an artifact of the virtualization that I am using for SAS University (i.e. VM)?  If so should I reinstall or perhaps use Oracle instead?


I am guessing that if I had the actual program installed on my hard drive the syntax that I am mimicking (in the numerous examples provided in various sources) would work.

Any help would be appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Your code is incorrect for SAS UE.

1. Make sure you've set up your VM correctly with the shared drive/folder.

2. Move the file to the shared location and then refer to it as '/folders/myfolders/myfile.csv'

3. As mentioned by BallardW the VM is unix so you need to use Unix path names.

4. Here's the FAQ/Help Centre that has code/help specific to SAS UE.

SAS University Edition Help Center

The relevant help consists of video which is annoying to me. Also search here under Analytics U section - there's a lot of similar questions regarding this issue.

View solution in original post

14 REPLIES 14
rantho02
Calcite | Level 5

FYI:  Here is the code that I am using from assorted help sources.

*Option 1: Use PROC IMPORT;

*PROC IMPORT datafile="Location of Your Data File on Hard Drive" dbms=extension of file without period out=name of new file;

PROC IMPORT datafile="C:\SAS\myfolders\datasets\SAS.dta" dbms=dta out=sasdata;

  RUN;

*Option 2: USE LIBNAME;

*LIBNAME libraryname "file path location";

*LIBNAME transportfilelibraryname XPORT "location and name of transport file";

*PROC COPY in=exportlibraryname out=datalibraryname;

*RUN;.

LIBNAME SASDATA "E:\SAS_University_Edition\mylibraries";

LIBNAME TEMP_A XPORT "E:\SAS_University_Edition\myfolders\datasets\SAS.dta";

PROC COPY in=TEMP_A out=SASDATA;

RUN;

Reeza
Super User

Your code is incorrect for SAS UE.

1. Make sure you've set up your VM correctly with the shared drive/folder.

2. Move the file to the shared location and then refer to it as '/folders/myfolders/myfile.csv'

3. As mentioned by BallardW the VM is unix so you need to use Unix path names.

4. Here's the FAQ/Help Centre that has code/help specific to SAS UE.

SAS University Edition Help Center

The relevant help consists of video which is annoying to me. Also search here under Analytics U section - there's a lot of similar questions regarding this issue.

rantho02
Calcite | Level 5

Thanks for the help.  I did not realize that the "Folders Tab" </folders/> in SASUE is a virtual folder that refers to  a physical location.


However, now I am getting this error:


1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;

42 ;

43

43 ! PROC IMPORT datafile="/folders/myfolders/SAS.dta" dbms=dta out=sasdata;

44 RUN;

For Stata, Release flags of 103 to 115 are supported. You had -> 60

Requested Input File Is Invalid

ERROR: Import unsuccessful. See SAS Log for details.

NOTE: The SAS System stopped processing this step because of errors.

NOTE: PROCEDURE IMPORT used (Total process time):

  real time 0.00 seconds

  cpu time 0.01 seconds

  

45 ;

46 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;

56 ;

ballardw
Super User

DBMS=STATA instead of DTA perhaps?

rantho02
Calcite | Level 5

Nope that wasn't it.  Still the same error and log results.

ballardw
Super User

Is the file actually a STATA data set or something else?

rantho02
Calcite | Level 5

It is STATA data. I also have .xpt format but PROC IMPORT will not let me use it (there is no dbms for it).  I have tried the LIBNAME method to import the .xpt format, but I get the following error:

*My Program;

  LIBNAME SASUSER "/folders/myfolders/";

  LIBNAME SASUSERx "/folders/myfolders/";

  LIBNAME SASUSERX XPORT "/folders/myfolders/SAS.xpt";

  PROC COPY in=SASUSERX out=SASUSER;

  RUN;

1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;

42 ;

43 LIBNAME SASUSER "/folders/myfolders/";

NOTE: Libref SASUSER was successfully assigned as follows:

  Engine: V9

  Physical Name: /folders/myfolders

44 LIBNAME SASUSERX "/folders/myfolders/";

NOTE: Libref SASUSERX refers to the same physical library as SASUSER.

NOTE: Libref SASUSERX was successfully assigned as follows:

  Engine: V9

  Physical Name: /folders/myfolders

46 LIBNAME SASUSERX XPORT "/folders/myfolders/SAS.xpt";

ERROR: At least one file associated with fileref SASUSERX is still in use.

ERROR: Error in the LIBNAME statement.

  180

ERROR 180-322: Statement is not valid or it is used out of proper order.

49 PROC COPY in=SASUSERX out=SASUSER;

50 RUN;

51

52 ;

53 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;

63 ;

Reeza
Super User

What version of STATA is the file created with?

Unix doesn't support libname access to files AFAIK.

Also, leave out the DBMS option and give that a try.

rantho02
Calcite | Level 5

Stata Version 13.1.

I do not know what "AFAIK" is and I have never use Unix.

I did try to leave out the dbms but it would not run.

If I could get the .xpt file to run (created by Stata) that would be fine too (perhaps better since it forces SAS naming for variables)

Reeza
Super User

The VM is on a UNIX box so UNIX rules apply. AFAIK is as far as I know.

Can you post the file? If not contact SAS tech support - sasanalyticsu@sas.com

Also when STATA creates the XPT file doesn't it create a .SAS file as well? Do you have that file?

rantho02
Calcite | Level 5

I have attached a small sample since the original file is over 100MB. Thanks again for the help.

Reeza
Super User

Your code for the import of the XPT file was incorrect and that method works. The DBMS method with DTA or STATA results in an error.

/*DOES NOT WORK*/

proc import datafile='/folders/myfolders/example.dta'

    dbms=stata out=example replace;

run;

/*WORKS*/

libname sample XPORT '/folders/myfolders/example.xpt';

proc copy in=sample out=work;

run;quit;

libname sample;

rantho02
Calcite | Level 5

Thanks for all the help.  Once I changed the out=WORK then it worked (lol).  I was under the impression from the examples that I saw that I had to create my own library to hold the data once it was created.  But if I just have to use WORK that is fine with me. Now if only SAS had a "help" command with exacting documentation and examples like Stata...Smiley Wink

Hope this helps others looking to do the same thing.

ballardw
Super User

Please post an example of the error.

However we have seen this topic many times. The most likely causes are either or both of:

1) the import data is not subordinate to myfolders, the University Edition and virtual machine only see things at that level. This is definitely part of the problem if you see a file name like /folders/myfolders\C:\mypath\mydata.dat in the file does not exist message.

2) the file and path names are case sensitive if your try to use file Myimport.data and the name is actually MyImPort.Data then it fails. This is part of the Linux/Unix behavior of the virtual machine.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 14 replies
  • 5059 views
  • 4 likes
  • 3 in conversation