BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DavidPhillips2
Rhodochrosite | Level 12

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.

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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.));

--
Paige Miller

View solution in original post

7 REPLIES 7
PaigeMiller
Diamond | Level 26

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?)

--
Paige Miller
DavidPhillips2
Rhodochrosite | Level 12

How can I increment a macro variable by one year? 

PaigeMiller
Diamond | Level 26

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.));

--
Paige Miller
ballardw
Super User

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

DavidPhillips2
Rhodochrosite | Level 12

date would be better

slchen
Lapis Lazuli | Level 10
%let startYear ="1Jul2015:0:0:0"dt;
%let newstarYear=%sysfunc(putn(%sysfunc(intnx(dtyear,&startYear,1,s)),datetime19.));
%put &newstarYear;
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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).

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 7 replies
  • 1421 views
  • 0 likes
  • 5 in conversation