BookmarkSubscribeRSS Feed
Nyioves
Calcite | Level 5

I can't figure out a way to use an infile statement that will actually work. I put in the whole path and it doesn't work. I've tried assigning a libref and then the name of the file  eg infile mylib.myfile.

I tried quotes everything. can it not read raw data ?

12 REPLIES 12
ballardw
Super User

You should be getting error messages. Please post some of them.

Reeza
Super User

Yes, but you usually need to upload the data to the server, it can't access data on your desktop AFAIK. You usually need to be a professor to accomplish this as well.

There are quite a few posts on here regarding this issue. 

Nyioves
Calcite | Level 5

ERROR: Physical file does not exist, /pbr/biconfig/940/Lev1/SASApp/country.dat.

looks like it's looking elsewhere for it despite the libname was assigned succefully

I can't find anything on this topic w google incidentally

Tom
Super User Tom
Super User

You do not read a text file using a libref.  You can use a fileref.  Or you can just use a quoted physical path.

If your LIBNAME statement executed without error then you could try using the same path to reference the file.

Make sure to use a fully qualified path, because otherwise SAS will look for the file starting the current working directory which is usually not your path but part of the SAS installation.

%let path=/home/....... ;

libname out "&path" ;

data out.new ;

infile "&path/myfile.csv" dsd firstobs=2 ;

input var1-var5;

run;

Cynthia_sas
SAS Super FREQ

Hi:

  These 2 previous postings specifically show reading COUNTRY.DAT with an INFILE statement:

INFILE statement for PRG1 on Univ Edition:

  https://communities.sas.com/message/222742#222742 (example country.dat)

  https://communities.sas.com/message/224467#224467 (example country.dat)

  And, I believe that COUNTRY.DAT is used in the Programming 1 course. In the e-learning course, the instructions in the Course Overview section have you explicitly set a macro variable called PATH like this:

%let path = /folders/myfolders/ecprg193;

which means that the correct INFILE statement for COUNTRY.DAT would be one of these (assuming that you followed the instructions and made an ECPRG193 directory):

INFILE '/folders/myfolders/ecprg193/country.dat' dlm='!';

INFILE "&path/country.dat" dlm='!';

  If you are still using your course notes from Programming 1 and Programming 2, as you indicated in this posting, https://communities.sas.com/message/257003#257003 then you would follow the instructions in the first demo in Chapter 1.

cynthia

Nyioves
Calcite | Level 5

I am really confused.

1. I'm using On Demand not the virtual machine.

2. %Let is not something I am familiar with

3. I'm using Country.dat for my own reasons and not necessarily following the course notes.

4. When I use a libname statement and a set statement to read a SAS file; it works. Why wouldn't the same libname statement with an infile statement to read raw data (in the same folder as the SAS data set) not work also?

And please reply with just an infile statement that contains the syntax I should be using. Thanks.

Cynthia_sas
SAS Super FREQ


Hi:

  If you are using SAS OnDemand for Academics, then instead of /folders/myfolders you would use your /home directory, as shown in your SAS OnDemand Control Center:

/home/<your_username>/ecprg193/country.dat so if your username is nyioves, for example and if you did make a folder called ecprg193 for the data then the infile would be:

infile '/home/nyioves/ecprg193/country.dat' dlm='!'; OR, if you make a different file for the course programs, then the infile would be:
    

infile '/home/nyioves/prg1/country.dat' dlm='!';
      

The LIBNAME points to SAS datasets--so the LIBNAME statement will NOT contain any reference to a specific file name and file extension. On the other hand, the INFILE statement points to raw data files, so the INFILE statement should have a reference to a specific file. So if you have a LIBNAME statement like this:

libname orion '/home/nyioves/ecprg193';
     

then your INFILE statement should be the SAME as the high level path with the raw data file name specified at the end.

infile '/home/nyioves/ecprg193/country.dat' dlm='!';

You said that you have a working LIBNAME statement. Assuming that country.dat is in the same location as the SAS datasets, then you should be able to use the path from your LIBNAME statement. But without knowing 1) your username and 2) the name of the folder you have, it is impossible to just give you just the syntax that you should be using.

cynthia

Nyioves
Calcite | Level 5

Tom got it but not necessarily I think for the reasons he montioned. You need a fileref since course has 2 Country files -- .dat and a SAS.

Anyway you need a fileref....

filename nikfile '/home/nyioves/Nikfold/country.dat';

data myfil;

infile nikfile dlm '!';

input var1 $ var2 $;

run;

Reeza
Super User

You do read text files and SAS files differently in SAS. You use a libname to reference SAS (.sas7bdat) datasets and filerefs to reference text files.

You can also reference a text file directly in the data step. If your question is answered please mark it answered.

ie.

data myfil;

infile '/home/nyioves/Nikfold/country.dat' dlm '!';

input var1 $ var2 $;

run;

Cynthia_sas
SAS Super FREQ

Hi, there are several different ways to point to external files:


1) using a FILEREF and an INFILE statement:
filename wombat '/home/<username>/subdir/filename.ext';

 
data work.new;
  infile wombat dlm=',';
... more code...;
run;

    

2) direct reference:
data work.new;
  infile '/home/<username>/subdir/filename.ext' dlm=',';
... more code...;
run;


3) combined or "member" reference:
filename wombat '/home/<username>/subdir';

 

data work.new;
  infile wombat(filename.ext) dlm=',';
... more code...;
run;

The key is understanding the path name and that the filename/extension are needed for all 3 methods: #1 and #2, the filename and extension are needed in either the FILENAME or INFILE statement and for method #3, the FILENAME statement does NOT have the file name and extension, but the INFILE statement does have the name and extension.

Cynthia 

NabilIbrahim
Calcite | Level 5
Thanx a lot Cynthia, you're very useful 🙂

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
  • 12 replies
  • 6351 views
  • 5 likes
  • 6 in conversation