Specifying a file name as a variable in an infile statement

I bind to convert a comma delimited text file to a channel delimited file, but my input file name (comma delimited file) is a variable (flname1). I am using the code suggested by the stackoverflow element. The code works fine as long as I specify the file name in the infile statement, but I don't know how to specify the file name as a variable -

data _null_;
   enddate=date();
   flname1=compress("d:\temp\wq_" || year(enddate) || put(month(enddate),z2.) || ".txt");
   length x1-x6 $200;
   infile 'flname1' dsd dlm=',' truncover;
   file 'C:\temp\pipe.txt' dsd dlm='|';
   input x1-x6;
   put x1-x6;
run;

I am new to SAS and any help would be greatly appreciated. Thanks!

+4
source share
2 answers

, - filevar ( , - ).

%let filename = d:\temp\wq_%sysfunc(today(),YYMMN6.).txt;
%put &=filename;

data _null_;
  length x1-x6 $200;
  infile "&filename." dsd dlm=',' truncover;
  file 'C:\temp\pipe.txt' dsd dlm='|';
  input x1-x6;
  put x1-x6;
run;

- , , . - , - .

%sysfunc, SAS today(), , - YYMMN6. - , (201506 ). , " , ' , .

0

filevar infile, :

data _null_;
  enddate=date();
  flname1=compress("d:\temp\wq_"||year(enddate)||put(month(enddate),z2.)||".txt");
  length x1-x6 $200;
  infile myinputfile dsd dlm=',' filevar=flname1 truncover;
  file 'C:\temp\pipe.txt' dsd dlm='|';
  input x1-x6;
  put x1-x6;
run;

documentation 5.

, Amir.

+2

Source: https://habr.com/ru/post/1614478/