BookmarkSubscribeRSS Feed
Timbim
Obsidian | Level 7

Hi All,

 

I am faily new to Macro and been a SAS user but not indepth.

 

I want to automate a step to import a daily CSV file into SAS.

 

How could I write a macro or sas step to import the file with today's date?

 

Greatly appreciate your help.

 

Thanks,

Maggie

2 REPLIES 2
Kurt_Bremser
Super User

You can create a macro variable that contains today's date in a proper format:

%let today=%sysfunc(today(),yymmdd10.);
%put &today;

If the date is part of the filename, you can then build the filename with the use of the macro variable.

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

The search bar can be used to find topics similar to what you are looking for, this kind of question gets asked at least once a week. In this case, you would need to provide more information such as - what is happening to the file before its gets to SAS, i.e. where is the file stored, is it overwriting a previous file (i.e. same name), or does it have differing names.  Is the data cumulative?  Is teh data exactly the same structurally?  It could just be as simple as having a program run daily which does this:

data in_data;
  infile "<path to files>/The_data_file_%sysfunc(today(),date9.).csv" dlm=",";
  input a $ b $;
run;

proc append base=master data=in_data;
run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 2 replies
  • 1286 views
  • 0 likes
  • 3 in conversation