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

Dear all,

 

Maybe you have a quick solution for this: 

I would like to create a timeseries for 48 months. Always get month end by providing a start date via a macro variable. My code below doesn't work. Any ideas?

So, Reporting_Date should look like:

31jan2020

29feb2020

31mar2020

...

 

%let startdate = '01jan2020'd;

data test;
 do t = 1 to 48;
  Reporting_Date = intnx('month', '&startdate.', t-1, 'E');
  output;
 end;
run;

 

Thanks!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

First of all, macro variables are not resolved when enclosed in single quotes. Second, you already have quotes in your macro variables, so that won't work either. Third, without a date format your results will not display right.

So do this:

%let startdate = 01jan2020;

data test;
format Reporting_Date yymmddd10.;
 do t = 1 to 48;
  Reporting_Date = intnx('month', "&startdate."d, t-1, 'E');
  output;
 end;
run;

View solution in original post

1 REPLY 1
Kurt_Bremser
Super User

First of all, macro variables are not resolved when enclosed in single quotes. Second, you already have quotes in your macro variables, so that won't work either. Third, without a date format your results will not display right.

So do this:

%let startdate = 01jan2020;

data test;
format Reporting_Date yymmddd10.;
 do t = 1 to 48;
  Reporting_Date = intnx('month', "&startdate."d, t-1, 'E');
  output;
 end;
run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 1 reply
  • 352 views
  • 1 like
  • 2 in conversation