datavoredan
datavoredan

Reputation: 3756

use a character date string as a date in data step

I have the following two macro variables:

%let start_date = 29MAY2014;
%let end_date = 15JUL2014;

I would like to create a dataset which is a series of dates between these (inclusive.) I cannot change the input format of the macro variables &start_date and &end_date.

I have tried many variations of the following, but SAS spits out an error for each:

data base_dates;
   do date = put("&start_date",date9.) to put("&end_date",date9.);
      output;
   end;
   format date date11.;
run;

Any help in this would be much appreciated

Upvotes: 0

Views: 56

Answers (2)

Reeza
Reeza

Reputation: 21274

Use them as date literals, enclose in quotes and add a d at the end.

Do date = "&start_date"d to "&end_date"d;

Upvotes: 1

datavoredan
datavoredan

Reputation: 3756

It was simple; input() instead of put()

data base_dates;
do date = input("&start_date",date9.) to input("&end_date",date9.);
output;
end;
format date date11.;
run;

Upvotes: 0

Related Questions