BookmarkSubscribeRSS Feed
98ighcfdvxcghjk
Calcite | Level 5

Hello,

 

I am trying to set up my dataset but I always forget what to do in order for SAS to read my dataset and the variables in it. This is what I have so far;


libname drug_a "c:\NidiaSAS\SASLearn\";
run;

PROC IMPORT DATAFILE= "c:\NidiaSAS|SASLearn\h188a"
out=
run;

The libname statement works but I forget what to do to make the dataset h188a go into the work folder so I can run tests on it. If anyone can help me without linking me to another forum that wont help me and just tell me what I should fix, I would appreciate it.

3 REPLIES 3
PaigeMiller
Diamond | Level 26

You would not use both PROC IMPORT on an Excel file and a LIBNAME statement pointing to the same Excel file.

 

Next, if you want the dataset created to go to the WORK library, you have to clean up the PROC IMPORT statement you typed, and specify the OUT= option.

 

PROC IMPORT DATAFILE= "c:\NidiaSAS\SASLearn\h188a.xlsx" out=h188a;

 

 

--
Paige Miller
ed_sas_member
Meteorite | Level 14

Hi @98ighcfdvxcghjk 

 

if your dataset is already a SAS dataset, there is no need to run a proc import -> just mention drug_a.h188a to refer to it

e.g.

libname drug_a "c:\NidiaSAS\SASLearn\";

Data test;
Set drug_a.h188a;
Run;

NB there is no need to put RUN after the libname statement.

 

if your dataset is a file (e.g. csv file), then do :

libname drug_a "c:\NidiaSAS\SASLearn\";

PROC IMPORT DATAFILE= "c:\NidiaSAS\SASLearn\h188a.csv"
out=drug_a.h188a
dbms = csv
replace;
run;

 

 

 

SASJedi
SAS Super FREQ

After you have successfully run the LIBNAME statement, you can test to see if your data set is already available using PROC CONTENTS:

proc contents data=drug_a.h188a;
run;

If your data is already there as a SAS data set, then you'll get a contents report and no errors in the SAS log. If your data was not in the library as a SAS data set, you'll get an error something like this:

 

ERROR: File DRUG_A.H188A.DATA does not exist. 

If your data is already a SAS data set, you don't need to copy it to the WORK library to use it. You can use it right from the "drug_a" library without the need to make a copy. For example:

proc means data=drug_a.h188a;
  class drug;
  var age;
run;

 

Check out my Jedi SAS Tricks for SAS Users

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

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