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

Hi,

 

Can anyone please confirm, if we can use data step to import a data set using programming in SAS enterprise guide? The data set is a SAS data set. We do not have to use proc import. Only by using a data step. Please share the code, if possible

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

You do not import a SAS dataset, you just use it. Copy the .sas7bdat file to a location that your SAS process has access to, define a libname for that location (if such has not already been defined), and you can use libname.dataset any place in your SAS code to use your data.

eg:

copy x:\somewhere\test.sas7bdat c:\temp
libname temp 'C:\temp';

proc print data=temp.test;
run;


@anubhav_200 wrote:

Suppose the data set is not a .sas7bdat file. Can we use a data step to read any data set, which is not in .sas7bdat file, say, a CSV file?

Yes. You not only CAN use the data step for this, you MUST use it. Even if you use the helper procedure proc import, it creates and runs a data step behind the scenes (you can take it from the log).

So imagine a csv file like this:

id,date,sum
A,2018-10-18,5

the data step to read it would look like this:

data want;
infile "location/name.csv" dlm=',' firstobs=2;
input
  id $
  date :yymmdd10.
  sum
;
format date yymmddd10.;
run;

Editor's Note:
Multiple responses were consolidated here to make the complete and final solution more accessible to future answer seekers 🙂 

View solution in original post

7 REPLIES 7
SASKiwi
PROC Star

You don't import a SAS dataset you just read it:

 

libname MyLibRef "c:\MyFolderWithSASData";

data MyDataset;
  set MyLibRef.MyDataset;
run;
Kurt_Bremser
Super User

You do not import a SAS dataset, you just use it.

Copy the .sas7bdat file to a location that your SAS process has access to, define a libname for that location (if such has not already been defined), and you can use libname.dataset in any place where you want to use your data.

eg:

copy x:\somewhere\test.sas7bdat c:\temp
libname temp 'C:\temp';

proc print data=temp.test;
run;
anubhav_200
Calcite | Level 5

Thanks Kurt!!

 

I just wanted to confirm that do we use the term importing or just reading the data set when we use a data step. Thanks for the response; it clarifies my doubt.

anubhav_200
Calcite | Level 5

A doubt in the answer that you have shared!

 

Suppose the data set is not a .sas7bdat file. Can we use a data step to read any data set, which is not in .sas7bdat file, say, a CSV file?

Kurt_Bremser
Super User

You do not import a SAS dataset, you just use it. Copy the .sas7bdat file to a location that your SAS process has access to, define a libname for that location (if such has not already been defined), and you can use libname.dataset any place in your SAS code to use your data.

eg:

copy x:\somewhere\test.sas7bdat c:\temp
libname temp 'C:\temp';

proc print data=temp.test;
run;


@anubhav_200 wrote:

Suppose the data set is not a .sas7bdat file. Can we use a data step to read any data set, which is not in .sas7bdat file, say, a CSV file?

Yes. You not only CAN use the data step for this, you MUST use it. Even if you use the helper procedure proc import, it creates and runs a data step behind the scenes (you can take it from the log).

So imagine a csv file like this:

id,date,sum
A,2018-10-18,5

the data step to read it would look like this:

data want;
infile "location/name.csv" dlm=',' firstobs=2;
input
  id $
  date :yymmdd10.
  sum
;
format date yymmddd10.;
run;

Editor's Note:
Multiple responses were consolidated here to make the complete and final solution more accessible to future answer seekers 🙂 

anubhav_200
Calcite | Level 5

Thanks, Kurt! I will try using the code shared by 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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 7 replies
  • 60596 views
  • 8 likes
  • 3 in conversation