BookmarkSubscribeRSS Feed
Mariaho
Calcite | Level 5

Hello,

I have the following files which are generated daily from another system which is date and time stamped.

I have a SAS process which is required to read in these daily files.

I have set up a macro variable so that it creates the date with the last business day %let file_date_m   = &file_date_yr.&file_date_mth.&file_date_day.;

As for the time, I would not know when it will be generated, my question is, how can I find the correct file for SAS to read in and can the time part be omitted ?

I would like to set up a macro variable like this (%let cdsfilename = "CDSALL0E_&file_date_m._&time.csv"n;) so that I can read in the correct file depending on the business day.

These files are being read in via PC Files Server.

Examples of the filenames:

CDSALL_20150810_081411.csv

CDSALL_20150811_073451.csv

CDSALL_20150812_072431.csv

CDSALL_20150813_080519.csv

CDSALL_20150814_075526.csv

CDSALL_20150817_080139.csv

CDSALL_20150818_071141.csv

CDSALL_20150819_082730.csv


Thank you.

3 REPLIES 3
ballardw
Super User

Execution time may be your bigger concern.

You can create a fileref with the name and date stem and ignore the time part using OS filesystem wildcards. In window.

Filename Input "c:\path\CDSALL_20150810_*.csv"; or use in an infile statement directly.

I am a tad concerned about this:

"CDSALL0E_&file_date_m._&time.csv"n

as you show an _m that does not appear in your input file name examples. Also the "n makes me think you are attempting to make a SAS variable name as most external file operations.

If you show some of the code how your are attempting to use the filename macro variable we might be able to provide some additional details.

data_null__
Jade | Level 19

You may be able to use a wild card in a FILEREF.  Consider the following example which create some files using the names you show and then reads the one from TODAY()-2.

data _null_;
  
input filename $64.;
   filevar=catx(
'/','~',filename);
   file dummy filevar=filevar dsd;
  
do i = 1 to 3;
     
put i filevar;
      end;
  
cards;
CDSALL_20150810_081411.csv
CDSALL_20150811_073451.csv
CDSALL_20150812_072431.csv
CDSALL_20150813_080519.csv
CDSALL_20150814_075526.csv
CDSALL_20150817_080139.csv
CDSALL_20150818_071141.csv
CDSALL_20150819_082730.csv
;;;;
   run;

%let target=%sysfunc(intnx(day,%sysfunc(today()),-2),yymmddn8);
%put NOTE: &=target;
filename FT45F001 "~/CDSALL_&target.*.csv";
data cds;
   length filename $128;
  
infile FT45F001 filename=filename dsd;
  
file=filename;
   input i filevar:$64.;
  
run;
proc print;
  
run;

Capture.PNG
Tom
Super User Tom
Super User

Why are you using PC FILES SERVER?  Does that mean that the actually machine that SAS is running on cannot see the files?  Because there should not be any other reason you need it since you can read a CSV file with BASE/SAS data step.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1237 views
  • 0 likes
  • 4 in conversation