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

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

View solution in original post

6 REPLIES 6
Tom
Super User Tom
Super User

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;

 

RavenWu
Calcite | Level 5

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?

 

 

 

 

Tom
Super User Tom
Super User

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;
RavenWu
Calcite | Level 5
Thank you!
LinusH
Tourmaline | Level 20
The data is in SAS as soon as you submit the libname statement.
Therefore, any references to it should NOT contain the physical file name of the data set.

References to it in a data step is done vis the SET statement, not INFILE.

There's a free on line SAS programming training where these concepts should be taught.
Data never sleeps
RavenWu
Calcite | Level 5
OK, THANK YOU!!!

SAS Innovate 2025: Call for Content

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!

Submit your idea!

How to Concatenate Values

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.

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
  • 6 replies
  • 1890 views
  • 0 likes
  • 3 in conversation