What about sorting the file after the fact instead?
The filename variable is character so that's a character ordering, test_1, test_100.
You can capture the filename in a variable and then extract the number. Then sort by that number.
data libname.test;
infile "&dlpath.\test_*.txt"
delimiter=','
missover
firstobs=1
DSD
lrecl = 32767 filename=filevar;
format column1 $12.;
format column2 yymmdds10.;
format column3 best12.;
file_name=filevar;
*this may need to be modified to capture the number based on the full path;
file_num=input(compress(file_name, , 'kd'), 8.);
input
column1 $
column2 :yymmdd8.
column3;
run;
proc sort data=libname.test;
by file_num column1 column2 column3;
run;
@AZFXL wrote:
I have multiple textfiles with sequentially incremental names, say test_1, test_2, ..., test_1000, each of them have exactly the same format (i.e. number of columns and delimited by comma). My intention is to append all these textfiles into one SAS database following the sequence of their filename. However, with the coding that I am currently using (as attached below), despite it will append all the textfiles, but the appending sequence is not as per my expectation (i.e, it will append test_1,test_10,...,test_19,test_100,...,test_199,test_1000,test_2,test_20,...,test_29,test_200,...,test_299,test_3,test_30,...,test_39,test_300,...,test_399,... instead of test_1, test_2, test_3, ..., test_1000).
As such, I am trying to explore the feasibility of using SAS macro to get the intended result. Appreciate if I could get any advice from the community to start off with the SAS macro, thank you very much in advance.
data libname.test;
infile "&dlpath.\test_*.txt"
delimiter=','
missover
firstobs=1
DSD
lrecl = 32767;
format column1 $12.;
format column2 yymmdds10.;
format column3 best12.;
input
column1 $
column2 :yymmdd8.
column3;
run;
... View more