I have seen some questions related to this in this forum, but still not very clear yet, so I would like to post my quesion here.
I want to read in a 'sas7bdat' , here is my codes:
LIBNAME Website 'D:\Desktop'; DATA Website; INFILE 'Websites.sas7bdat'; RUN;
It seems that the LIBNAME statement is usually used as a method to read a data with this format, I point out the path for SAS, then read inthis data by a DATA step,
The error appears:
ERROR: Physical file does not exist, C:\Windows\system32\Websites.sas7bdat.
I didn't point out the file to the C drive, so this error is weird. Could anybody tell me more about this?
SAS doesn't store datasets in memory like some other analytic tools. It reads the data from the disk when it needs to. This is why it does not have as many arbitrary limits on the size of dataset.
So if you want to use an existing data set with a procedure or data step then you just reference the dataset at the appropriate place. Hence the example PROC PRINT I posted before. If you want to run another data step to create some derived variables from your existing data then you would use a SET statement in your data step to reference the existing dataset.
data new ;
set 'websites.sas7bdat';
if last_mod > '01JAN2016'd then status = 'RECENT';
else status = 'STALE';
run;
You do not read a dataset like you would a text file. Instead you just reference it.
You can use the two level name approach like you started with. First create the library name (or LIBREF). You can then reference the data using libref.memname syntax.
You did not provide the name of the dataset you want to read so let's just assume it is actually a file named 'websites.sas7bdat' that is in the directory 'D:\'. So your syntax would be:
libname mylib 'D:\';
proc print data=mylib.websites;
run;
Now you can make it even easier by just using the quoted physical pathname of the file. SAS will automatically create a library for you.
proc print data="D:\websites.sas7bdat";
run;
Thank you very much @Tom , one more question, maybe a stupid question. You said 'You do not read a dataset like you would a text file. Instead you just reference it', so is the DATA-INFILE procedure also just procedure of referencing data?
DATA Website; INFILE 'Websites.sas7bdat'; RUN;
If I want to get this data into SAS, is there a way to do it? or say, for the sas7bdat file, normally we don't need to get it into SAS, instead, just reference it?
SAS doesn't store datasets in memory like some other analytic tools. It reads the data from the disk when it needs to. This is why it does not have as many arbitrary limits on the size of dataset.
So if you want to use an existing data set with a procedure or data step then you just reference the dataset at the appropriate place. Hence the example PROC PRINT I posted before. If you want to run another data step to create some derived variables from your existing data then you would use a SET statement in your data step to reference the existing dataset.
data new ;
set 'websites.sas7bdat';
if last_mod > '01JAN2016'd then status = 'RECENT';
else status = 'STALE';
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.