Help using Base SAS procedures

Importing data...

Reply
Occasional Contributor
Posts: 14

Importing data...

hi,

I have a dataset already created - by someone else - and they want me to run a bunch of frequency distributions on the data. My problem is that I don't know how to import a SAS dataset into a SAS program. I know how to do the analysis and I know how to run the procs, but I literally have no clue on how to get SAS data into SAS. If someone could please point me to an example of that on the web I would be grateful. Thank you very much.
Super Contributor
Posts: 291

Re: Importing data...

Assuming that you are in a Windows environment ...

Put the SAS data set in a directory, e.g. c:\temp

In SAS, create a libname statement, e.g.
libname mylibrary 'C:\temp';

proc print data=mylibrary.sasdatasetname;
run;

Same idea on any other platform
Occasional Contributor
Posts: 14

Re: Importing data...

This is not working...

I assigned the libname. My SAS program did not like the name mylibrary for whatever reason. I put in the correct directory.

And then I put in:

proc print data = freqs.matches_mh_dif_lal_g5.sas7bdat;
run;

and I get this error:

ERROR: Invalid data set name freqs.matches_mh_dif_lal_g5.sas7bdat.
ERROR: File WORK.MATCHES_MH_DIF_LAL_G5.DATA does not exist.
Super User
Posts: 5,260

Re: Importing data...

What SAS release are you running? On what platform?
And the input data, in what SAS release/platform was it created? How was it moved to it's current position?

If you do a

proc datasets lib=freqs;
quit;

is your input table visible in the log?
What is the exact name of your SAS data file?

/Linus
Data never sleeps
Occasional Contributor
Posts: 14

Re: Importing data...

SAS 9.1.3
Windows XP

The input data was created by a co-worker, who may or may not be using a more recent version. It was sent to me via email and I placed it in a folder.

Proc datasets returned all four of the "input tables" I need to create frequency distributions from. in fiddling around with it, just to figure what is going wrong I did this. I think the part I am missing is the actual inputting of the data. I just don't see any examples online where you input data that is already created. I don't need to assign variables. They were already assigned by someone else.

filename freqs 'P:\matches_mh_dif_lal_g5.sas7bdat';

libname temp 'P:\';

proc datasets lib=temp;
quit;

data temp.matches_mh_dif_lal_g5 infile freqs;
Proc print data=temp.matches_mh_dif_lal_g5 (obs=5);
run;
Super User
Posts: 5,260

Re: Importing data...

There is no need for you to input the data, it's accessible by SAS after the libname statement. Your error is that you refer to the physical name of the file. You should only refer to the logical table name (that is beacuse you program could move to ZOS where the physical tables have differnt structure/names).

libname temp 'P:\';
Proc print data=temp.matches_mh_dif_lal_g5 (obs=5);
run;

Be sure that the name after temp. matches the name in your proc datasets listing.

Then try to open the file in the SAS explorer, can you do that?

If this does not work, I suggest that you contact you co-worker to ask him to test this file, and maybe resend it in case it has been corrupted.

/Linus
Data never sleeps
Occasional Contributor
Posts: 14

Re: Importing data...

Ha... I checked the other three datasets and they ran fine... It is the ONE I was using to test that wasn't working... Such is life I suppose.
N/A
Posts: 0

Re: Importing data...

the reason why

LIBNAME mylibrary '';

did not work is that SAS require the libref to be no greater than 8 characters. It'll work fine if you use mylib instead.

:-)
Contributor
Posts: 28

Re: Importing data...

Wat are you using ...sas on unix/linux or windows create libname and check whether your data set apperas at explorer windows or not.............if it doesnt check whether its not the hidden one

Ask a Question
Discussion stats
  • 8 replies
  • 515 views
  • 0 likes
  • 5 in conversation