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
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 🙂
You don't import a SAS dataset you just read it:
libname MyLibRef "c:\MyFolderWithSASData";
data MyDataset;
set MyLibRef.MyDataset;
run;
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;
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.
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?
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 🙂
Thanks, Kurt! I will try using the code shared by you.
I strongly suggest you take the free Programming 1 E-Learning Course: https://support.sas.com/edu/schedules.html?ctry=us&crs=PROG1#s1=1
It will provide answers to this and other typical beginner questions.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.