STL
STL

Reputation: 293

Read a sas7bdat file in SAS Studio

I've scoured the internet but cannot seem to figure this out. My question is, if I have a sas7bdat file, how can I read a sas7bdat file in SAS studio so that I can work with it.

I've tried:

libname test 'C:\Users\name\Downloads\test.sas7bdat'; 

which gives me the error that library test does not exist and if I try the following, I know that I need an INPUT which I don't know of unless I can see into the file.

DATA test; 
    INFILE 'C:\Users\lees162\Downloads\test.sas7bdat'; 
RUN; 

Is there something I'm missing?

Upvotes: 1

Views: 27795

Answers (4)

Arpan Saini
Arpan Saini

Reputation: 5191

Suppose you have the sas dataset at location. C:\Users\name\Downloads\test.sas7bdat

libname download 'C:\Users\name\Downloads'; 

proc sql;

select * from downloads.test;

run;

you can read your dataset like a table using the proc sql, in case you want to query the dataset, but if you want to modify the existing dataset then you can use the data setp as mentioned by @krian.

Upvotes: 1

Vaibhav Kabdwal
Vaibhav Kabdwal

Reputation: 109

One possible reason could be that you are using the SAS University edition (It doesn't support variable library address).

From one of the SAS community Q/A:

"When you are using the SAS University Edition, any libraries that you create must be assigned to a shared folder. You access your shared folder with this pathname: /folders/myfolders/. Always use '/' in the directory path, even in Windows operating environments"

After setting the directory address, proceed as instructed by Tom above in one of the answers.

Upvotes: 1

Tom
Tom

Reputation: 51566

Libref's that you create via the LIBNAME statement point to directories, not individual files.

libname test 'C:\Users\name\Downloads\'; 

INFILE is for reading raw data files. To reference an existing SAS dataset you use a SET statement (or MERGE,MODIFY,UPDATE statement).

set test.test ;

Note that you can skip defining a libref and just use the quoted physical name in the SET statement.

DATA test; 
  set 'C:\Users\lees162\Downloads\test.sas7bdat'; 
RUN; 

Of course to use C:\ in the paths this is assuming that you are using SAS/Studio to point to full SAS running on your PC. If you are using SAS University Edition then it is running in a virtual machine and you will need to put the SAS dataset into a folder that is mapped to the virtual machine and then reference it in the SAS code with the name that the virtual machine uses for the directory.

So something like:

DATA test; 
  set '/folders/myfolders/test.sas7bdat'; 
RUN; 

Upvotes: 5

Kiran
Kiran

Reputation: 3315

Libname is just pointing the location and once you have done that you can use that libname followed period and dataset in your set statement

  libname test "C:\Users\name\Downloads"; 

 DATA test; 
 set  test.asl; 
 RUN; 

Upvotes: 3

Related Questions