gung - Reinstate Monica
gung - Reinstate Monica

Reputation: 11903

Can you make a fileref that works like a libref?

If you want to save datasets into a permanent library and don't want to continually retype the address, you can use LIBNAME:

LIBNAME d "C:\<file path>\My datasets"
DATA d.data1;
    ...
RUN;

Another feature to save typing is to use FILENAME:

FILENAME f "C:\<file path>\My datasets\data1.txt"
DATA d.data1;
    INFILE f;
    ...
RUN;

But this only works for one specific file, whereas d. can be used for any number of datasets. Is there a convenient way to tweak FILENAME or a different function / PROC so that it could be used like f.? For example:

DATA d.data1;
    INFILE f."data1.txt";
    ...
RUN;
DATA d.data2;
    INFILE f."data1.txt";
    ...
RUN;
DATA d.data3;
    INFILE f."data1.txt";
    ...
RUN;

Upvotes: 1

Views: 142

Answers (2)

Joe
Joe

Reputation: 63434

Another option, if you intend to use all files with a certain pattern in a directory, is to use a fileref with a wildcard.

filename f "c:\temp\*.txt";
data d.data1;
infile f;
.....
run;

Any normal wildcard combination for your OS should work (so, "data*.txt", "data_?.txt", etc. for Windows).

Upvotes: 1

scott
scott

Reputation: 2275

you can set your path to a macro variable and then use the macro variable in your file path call

example:

%let path = M:\file\path;

DATA d.data1;
infile = /*include path*/ "&path.\file_name.csv"
....
run;

Upvotes: 1

Related Questions