DATA Step, Macro, Functions and more

How to importing a sas7bdat

Accepted Solution Solved
Reply
Contributor
Posts: 20
Accepted Solution

How to importing a sas7bdat

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?


Accepted Solutions
Solution
‎07-20-2016 03:36 PM
Super User
Super User
Posts: 7,060

Re: How to importing a sas7bdat

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


All Replies
Super User
Super User
Posts: 7,060

Re: How to importing a sas7bdat

[ Edited ]

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;

 

Contributor
Posts: 20

Re: How to importing a sas7bdat

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?

 

 

 

 

Solution
‎07-20-2016 03:36 PM
Super User
Super User
Posts: 7,060

Re: How to importing a sas7bdat

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;
Contributor
Posts: 20

Re: How to importing a sas7bdat

Thank you!
Super User
Posts: 5,431

Re: How to importing a sas7bdat

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
Contributor
Posts: 20

Re: How to importing a sas7bdat

OK, THANK YOU!!!
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 492 views
  • 0 likes
  • 3 in conversation