Donotello
Donotello

Reputation: 157

How to reference file correctly in filevar option in SAS?

Here is a simple code to read two files

filename one "C:\Users\Owner\Desktop\SAS\nbExce\ch1\1-12 one.txt" ; 
filename two "C:\Users\Owner\Desktop\SAS\nbExce\ch1\1-12 two.txt" ; 

data test ; 
input extfile $ ; 
infile dummy filevar=extfile end=last ;
do until (last) ;
input name $ score ;
output ;
end ;
datalines ;
one
two
;
run ; 

proc  print ;
run ;

Why do I get this error ? How can I improve my file references ?

Upvotes: 1

Views: 595

Answers (1)

Laurent de Walick
Laurent de Walick

Reputation: 2174

You cannot refer to file assigned using a filename statement in the filevar. Use the full path to the files.

data test;
 infile datalines dsd; 
 length extfile $128;
 input extfile $; 
 infile dummy filevar=extfile end=last;
 do until (last);
  input name $ score;
  output;
 end;
datalines;
"C:\Users\Owner\Desktop\SAS\nbExce\ch1\1-12 one.txt"
"C:\Users\Owner\Desktop\SAS\nbExce\ch1\1-12 two.txt"
;
run;

Upvotes: 1

Related Questions