How to automate and import files that are located

2019-03-01 12:42发布

问题:

I currently have 700 folders that are all sequentially named.

The naming convention of the folders are as follows:-

2011-08-15_2011-08-15    
2011-08-16_2011-08-16
2011-08-17_2011-08-17
...
2013-09-20_2013-09-20

There are 10 txt files within each folder that have the same naming convention.

With the txt files all being the same, what I am trying to achieve is to automate the infile and then use the name of the folder, eg 2011-08-15_2011-08-15 or part of eg. 2011-08-15 to then be the name of the created data set.

I can successfully import all the txt files so there is no issue there, the issue is i don't want to be changing the folder name each time in the infile step.

'C:\SAS data\Extract\2011-08-17_2011-08-17\abc.txt'

Is there an easier way to read these files in? I can find code for sequential txt/csv files but can find nothing to reference a folder and then rename the data set.

回答1:

You should be able to wildcard the folders/files into a single fileref, e.g.

filename allfiles "c:\SAS_data\extract\*\*.txt" ;

data alldata ;
  length fn _fn $256. ;
  infile allfiles lrecl=256 truncover filename=_fn ;
  fn = _fn ; /* Store the filename */
  input ;
  put _INFILE_ ;
run ;

The wildcard folder & file works in SAS Unix, not sure about SAS PC.



标签: sas