BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I am trying to increment a date by one day so it is the beginning of a month and have it appear in a report title. Once I have the answer, the date will be a variable selected by the user that is actually an end-of-month date.

%let x=intnx('DAY', '31Mar08'd,1);
%put x / x date9.;

TITLE;
TITLE1 "Date = &x";

Here's the results in the report:

Date = intnx('DAY', '31Mar08'd,1)

I would like it to show Date = 04/01/2008.

Any ideas??
5 REPLIES 5
andreas_lds
Jade | Level 19
The problem is that you are mixing macro-code and normal sas-code. In this case the intnx-function will never be executed. Some functions can be used in macro-statements via the %sysfunc-macro-function.

The following code uses a data-step to create the macro-variable firstDay.

[pre]
data _null_;
firstDay = put(intnx("DAY", "31Mar08"d, 1), mmddyy8.);
call symput("firstDay", firstDay);
run;

TITLE;
TITLE1 "Date = &firstDay";

proc print data=sashelp.class;
run;
[/pre] Thinking before the first coffee is not always a good idea 😉 I removed the wrong idea about intnx and sysfunc.


Message was edited by: andreas_lds
LinusH
Tourmaline | Level 20
If you know that your base date is the last date of the previous month, just add 1:

date = input_date + 1;

Otherwise, you could try:

date = intnx('MONTH',input_date,1,'BEGINNING');

/Linus
Data never sleeps
deleted_user
Not applicable
%SYSFUNC supports the intnx functions

%let x=%sysfunc(intnx(day,"31Mar2008"d,1,B),ddmmyy8.);
%put &x;

04/01/08


Hope this could be handy.
Sridhar.
deleted_user
Not applicable
Thank you. This worked when I "hard code" the date that I need to increment. I'm having trouble now when I want to use a parameter value that the user selected.

%let beg_date = &Prior_Month_End;
TITLE1 "&beg_date";

Result: '31Mar2008:0:0:0'dt

When I try to put Prior_Month_End in the sysfunc
%let beg_date = %sysfunc(intnx(day,&prior_month_end,1,beginning));
Result: . (period)

w/out the '&' on Prior_Month_End, I get an error message.

When I try it a different way, it appears the "value" for Prior_Month_End "starts at 1/1/1960.
%let beg_date = %sysfunc(intnx(day,%sysfunc(Datepart(&Prior_Month_End),
mmddyys10.),1),mmddyys10.);
Result: 01/02/1960

Any more help would be appreciated.
LinusH
Tourmaline | Level 20
Sorry, I don't get the full picture here.
Does &Prior_Month_End has datetime value?
Is this only used for your title statement?

If it's only for displaying a %substr would do:

TITLE1 "%substr(&beg_date,2,9)";

If you want to use for some subset, I guess you need to get the datepart out of it, here you can use %substr as well (as long as you are sure of the format of the value):


%let beg_date = "%substr(&Prior_Month_End,2,7)"d;

Or nicer, working with a SAS date function:

%let beg_date = %sysfunc(datepart(&a));

Hope this helps,
Linus
Data never sleeps

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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