BookmarkSubscribeRSS Feed
Milo08
Calcite | Level 5
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.
8 REPLIES 8
Bill
Quartz | Level 8
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
Milo08
Calcite | Level 5
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.
LinusH
Tourmaline | Level 20
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
Milo08
Calcite | Level 5
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;
LinusH
Tourmaline | Level 20
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
Milo08
Calcite | Level 5
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.
deleted_user
Not applicable
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.

:-)
LearnByMistk
Obsidian | Level 7

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 1650 views
  • 0 likes
  • 5 in conversation