Martin Reindl
Martin Reindl

Reputation: 1603

Print a CSV file from SAS using libname

I am trying to export data from SAS into a CSV file from a table I created using PROC SQL. (test_data was created using a PROC SQL Select statement) I tried the following code:

LIBNAME libout "C:\Users\Outbox";
proc export data=test_data dbms=csv replace outfile="&libout.\test_data.csv";
run;

When running this code snipped the following error shows up:

ERROR: Physical file does not exist, C:\windows\system32\&libout.\test_data.csv.

I know I can specify the path using a string for outfile directly, but I am trying to use a LIBNAME for later application in another system instead. Thanks in advance.

Upvotes: 0

Views: 3040

Answers (2)

Joe
Joe

Reputation: 63434

libname is for SAS dataset; filename is for files.

filename fileout "C:\Users\Outbox\test_data.csv";
proc export data=test_data dbms=csv replace outfile=fileout;
run;

You could also use a macro variable if you want to just specify the directory, similar to Superfluous's answer. But don't put quotes around it there.

%let outdir = c:\users\outbox;
proc export data=test_data dbms=csv replace outfile="&outdir.\test_data.csv";
run;

In either case you can specify the filename or the macro variable in one location and then use it in a very different location, they don't have to be sequential - just like libnames.

Upvotes: 1

Sean
Sean

Reputation: 1120

You would use a libname if you wanted to store a SAS dataset. In this case, you want to save a csv file, so you just need a macro: %let libout = "C:\Users\Outbox";

Upvotes: 0

Related Questions