DATA Step, Macro, Functions and more

Add a Year to a Date Macro

Accepted Solution Solved
Reply
Super Contributor
Posts: 477
Accepted Solution

Add a Year to a Date Macro

I have a macro like:

%let startYear = '1Jul2015:0:0:0'dt;

How can I add a year to the macro? All the examples I have seen have added a year in the dataset rather than the macro.


Accepted Solutions
Solution
‎11-24-2015 09:00 AM
Trusted Advisor
Posts: 1,606

Re: Add a Year to a Date Macro

Oh, duh, that should have been obvious but I guess I misread your question.

 

%let incr_by_one_year=%sysfunc(intnx(dtyear,&startyear,1,s));

%put incr_by_one_year %sysfunc(putn(&incr_by_one_year,datetime16.));

View solution in original post


All Replies
Trusted Advisor
Posts: 1,606

Re: Add a Year to a Date Macro

I don't understand the question. Your example already has a year in it.

 

(And we're talking about a macro variable, not a macro, right?)

Super Contributor
Posts: 477

Re: Add a Year to a Date Macro

How can I increment a macro variable by one year? 

Solution
‎11-24-2015 09:00 AM
Trusted Advisor
Posts: 1,606

Re: Add a Year to a Date Macro

Oh, duh, that should have been obvious but I guess I misread your question.

 

%let incr_by_one_year=%sysfunc(intnx(dtyear,&startyear,1,s));

%put incr_by_one_year %sysfunc(putn(&incr_by_one_year,datetime16.));

Super User
Posts: 10,460

Re: Add a Year to a Date Macro

Is there any particular reason you call a datetime value a date?

Super Contributor
Posts: 477

Re: Add a Year to a Date Macro

date would be better

Super Contributor
Posts: 275

Re: Add a Year to a Date Macro

%let startYear ="1Jul2015:0:0:0"dt;
%let newstarYear=%sysfunc(putn(%sysfunc(intnx(dtyear,&startYear,1,s)),datetime19.));
%put &newstarYear;
Super User
Super User
Posts: 7,392

Re: Add a Year to a Date Macro

Personally I would never use macro varaibles (which are text) for manpulating or using date/time numeric data.  I would put them in a parameters dataset, and call them up when needed.  Two beneifts, you can manipulate them using the full simple syntax of base SAS, and they are accessible in numerous manners (i.e. call symput, join/merge, call execute).

☑ This topic is SOLVED.

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

Discussion stats
  • 7 replies
  • 330 views
  • 0 likes
  • 5 in conversation