03-30-2015 03:42 PM
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 ?
03-30-2015 03:51 PM
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.
03-30-2015 04:58 PM
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
03-30-2015 07:29 PM
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 ;
03-30-2015 07:43 PM
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.
03-31-2015 09:55 AM
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.
03-31-2015 10:09 AM
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.
03-31-2015 10:14 AM
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';
infile nikfile dlm '!';
input var1 $ var2 $;
03-31-2015 10:40 AM
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.
infile '/home/nyioves/Nikfold/country.dat' dlm '!';
input var1 $ var2 $;
03-31-2015 12:40 PM
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';
infile wombat dlm=',';
... more code...;
2) direct reference:
infile '/home/<username>/subdir/filename.ext' dlm=',';
... more code...;
3) combined or "member" reference:
filename wombat '/home/<username>/subdir';
infile wombat(filename.ext) dlm=',';
... more code...;
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.