Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading in an existing dataset

Status
Not open for further replies.

dkaplan

Programmer
Jan 29, 2001
98
0
0
US
I am just learning sas and something very simple is eluding me.

I am trying to read specific variables from an existing dataset into a new dataset. I tried something like

data newdataset;
infile olddataset;
input col1 col2;
run;

but I get an error? Can infile only be used with raw data files? i.e. infile = "c:\dirName\rawFile.txt";
Or can it also pull in an existing dataset?
 
You;re right, infile is for raw files, txt, csv, dat etc etc

If your exsisting dataset is in your work library you can simply do:

data newdataset (keep = col1 col2);
set olddataset;
run;

Or if the exsisting dataset isnt in your work library but elsewhere you can use a libname statement:

libname lib1 'c:\mysas' /*where lib1 is your choice of library name and were C:\.. is the path to the dataset*/

data newdataset (keep = col1 col2);
set lib1.olddataset;
run;
 
Thanks, jj72uk.

This works perfectly.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top