Using Dates with Nested Macro Variables and DO Loop

Accepted Solution Solved
Reply
Contributor
Posts: 20
Accepted Solution

Using Dates with Nested Macro Variables and DO Loop

Hello,

I have many files that I would like to import that have a date component in the file name (for example, the file '20130131_BKV_imps.zip' contains data for 1/31/2013).

I am attempting call in the names of each file by creating two 'nested' macro variables ('length' & 'zip_start') from other macro variables ('startdate' and 'enddate') and a DO loop to increment 'i' until it equals 'length'.

In the below example, I'm attempting to call up the names of each file from 1/1/2013 - 2/1/2013 (31 files).  I can't get either nested variable to evaluate as I want.  Any suggestions?

Here is my code:

%let startdate='01Jan2013'd; %put %sysfunc(putn(&startdate,mmddyy.));

%let enddate='01Feb2013'd; %put %sysfunc(putn(&enddate,mmddyy.));

%let length=%eval(&enddate-&startdate); %put &length;

/* want length = 31 */

%macro impressions;

%do i = 0 %to &length;

%let zip_start=year(&startdate+&i)|month(&startdate+&i)|day(&startdate+&i)|'_BKV_imps'; %put &zip_start;

/* want this format for zip_start: 20130226_BKV_imps*/

%end;

%mend impressions;

%impressions;

I m using Enterprise Guide 5.1 with SAS 9.3


Accepted Solutions
Solution
‎05-31-2013 02:55 PM
Super User
Super User
Posts: 7,039

Re: Using Dates with Nested Macro Variables and DO Loop

Posted in reply to leeklammer

Looks like you are working too hard.

%let startdate=01Jan2013;

%let enddate=01Feb2013;

%macro impressions;

  %do i = %sysfunc(inputn(&startdate,date9.)) %to %sysfunc(inputn(&enddate,date9.)) ;

    %let zip_start=%sysfunc(putn(&i,yymmddn8.))_BKV_imps;

    %put i=&i zip_start=&zip_start ;

  %end;

%mend impressions;

%impressions;

i=19359 zip_start=20130101_BKV_imps

i=19360 zip_start=20130102_BKV_imps

...

i=19389 zip_start=20130131_BKV_imps

i=19390 zip_start=20130201_BKV_imps

View solution in original post


All Replies
Solution
‎05-31-2013 02:55 PM
Super User
Super User
Posts: 7,039

Re: Using Dates with Nested Macro Variables and DO Loop

Posted in reply to leeklammer

Looks like you are working too hard.

%let startdate=01Jan2013;

%let enddate=01Feb2013;

%macro impressions;

  %do i = %sysfunc(inputn(&startdate,date9.)) %to %sysfunc(inputn(&enddate,date9.)) ;

    %let zip_start=%sysfunc(putn(&i,yymmddn8.))_BKV_imps;

    %put i=&i zip_start=&zip_start ;

  %end;

%mend impressions;

%impressions;

i=19359 zip_start=20130101_BKV_imps

i=19360 zip_start=20130102_BKV_imps

...

i=19389 zip_start=20130131_BKV_imps

i=19390 zip_start=20130201_BKV_imps

Contributor
Posts: 20

Re: Using Dates with Nested Macro Variables and DO Loop

You're the man, Tom!  Thanks very much.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 346 views
  • 1 like
  • 2 in conversation