Adrian
Adrian

Reputation: 784

assign a path to a file, in SAS

I have the following code, which works in SAS Studio:

DATA test;
INFILE "/folders/myfolders/sasuser.v94/test.csv"
    DLM=","
    FIRSTOBS=2;
INPUT ID V1 V2;
RUN;

The task is to assign the path earlier to an object and use it later, something similar to:

%LET myfile="/folders/myfolders/sasuser.v94/test.csv";
DATA test;
INFILE myfile
    DLM=","
    FIRSTOBS=2;
INPUT ID V1 V2;
RUN;

However, this generates an error in SAS "No logical assign for filename MYFILE"

Is there any possibility to achieve this? I have only a very basic SAS understanding, and I was told that SAS requires setting a LIBNAME first, but I have no idea how to combine the LIBNAME (essentially the working folder) with the file name "test.csv" that I need to import.

Thanks in advance, Adrian

Upvotes: 0

Views: 1300

Answers (1)

DaBigNikoladze
DaBigNikoladze

Reputation: 661

you can use one of the following two forms:

%LET myfile="/folders/myfolders/sasuser.v94/test.csv";
DATA test;
    INFILE &myfile.;

or

FILENAME myfile "/folders/myfolders/sasuser.v94/test.csv";
DATA test;
    INFILE myfile;

Upvotes: 4

Related Questions