date Macro

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 8
Accepted Solution

date Macro

Hi All,

Please i need help on this macro below.

%macro appnd(currmth);

 

data _null_;

call symput('start',intnx('month',input(('01'||put("&CURRMTH",$7.)),date9.),0,'begin'));

call symput('end',intnx('month',input(('01'||put("&CURRMTH",$7.)),date9.),0,'end'));

run;

data _null_;

call symput('ddend',intck('day',&start.,today()));

call symput('dstart',intck('day',&end.,today()));

run;

%do i=   &dstart.%to &ddend. ;

data _null_;

call symput("pday",put(intnx("day",date(),-&i.,'end'),date9.));

call symput("dday",put(intnx("day",date()-1,-&i.,'begin'),date9.));

run;

%put &dday &pday

%end;

%mend;

%appnd(DEC2010);

The output &dday &pday

are

31DEC2010 30DEC2010

30DEC2010 29DEC2010

29DEC2010 28DEc2010

---

But i want it to start like this

01DEC2010 30NOV2010

02DEC2010 01DEC2010

03DEC2010 02DEC2010

----

Please help

Timmy


Accepted Solutions
Solution
‎05-16-2014 01:41 PM
Super User
Posts: 17,785

Re: date Macro

See 4 posts above.

View solution in original post


All Replies
Super User
Posts: 17,785

Re: date Macro

That's not the output I get (see below). What are you trying to do?

You're missing a semicolon in your put statement.

30DEC2010 31DEC2010

29DEC2010 30DEC2010

28DEC2010 29DEC2010

27DEC2010 28DEC2010

26DEC2010 27DEC2010

25DEC2010 26DEC2010

24DEC2010 25DEC2010

23DEC2010 24DEC2010

22DEC2010 23DEC2010

21DEC2010 22DEC2010

20DEC2010 21DEC2010

19DEC2010 20DEC2010

18DEC2010 19DEC2010

17DEC2010 18DEC2010

16DEC2010 17DEC2010

15DEC2010 16DEC2010

14DEC2010 15DEC2010

13DEC2010 14DEC2010

12DEC2010 13DEC2010

11DEC2010 12DEC2010

10DEC2010 11DEC2010

09DEC2010 10DEC2010

08DEC2010 09DEC2010

07DEC2010 08DEC2010

06DEC2010 07DEC2010

05DEC2010 06DEC2010

04DEC2010 05DEC2010

03DEC2010 04DEC2010

02DEC2010 03DEC2010

01DEC2010 02DEC2010

30NOV2010 01DEC2010

Occasional Contributor
Posts: 8

Re: date Macro

Hi Reeza,

Sorry Reeza i missed the semi colon which i have added.

My problem is i don't want the order of the date.

I want it the other way round like this below

01DEC2010 30NOV2010

02DEC2010 01DEC2010

03DEC2010 02DEC2010

04DEC2010 03DEC2010


Please i need help on this macro below.

%macro appnd(currmth);

data _null_;

call symput('start',intnx('month',input(('01'||put("&CURRMTH",$7.)),date9.),0,'begin'));

call symput('end',intnx('month',input(('01'||put("&CURRMTH",$7.)),date9.),0,'end'));

run;

data _null_;

call symput('ddend',intck('day',&start.,today()));

call symput('dstart',intck('day',&end.,today()));

run;

%do i=   &dstart.%to &ddend. ;

data _null_;

call symput("pday",put(intnx("day",date(),-&i.,'end'),date9.));

call symput("dday",put(intnx("day",date()-1,-&i.,'begin'),date9.));

run;

%put &dday &pday;

%end;

%mend;

%appnd(DEC2010);

The output &dday &pday

are

31DEC2010 30DEC2010

30DEC2010 29DEC2010

29DEC2010 28DEc2010

---

But i want it to start like this

01DEC2010 30NOV2010

02DEC2010 01DEC2010

03DEC2010 02DEC2010

----

Please help

Timmy

Super User
Posts: 17,785

Re: date Macro

Simplified a bit, can probably be simplified more.

%macro appnd(currmth);

data _null_;

call symput('start',intnx('month',input(('01'||put("&CURRMTH",$7.)),date9.),0,'begin') );

call symput('end',intnx('month',input(('01'||put("&CURRMTH",$7.)),date9.),0,'end'));

run;

%PUT &START. ;

%PUT &END ;

%do i=   &start. %to &end. ;

data _null_;

call symput("dday",put(&i,date9.));

call symput("pday",put(intnx("day",&i, -1),date9.));

run;

%put &dday &pday;

%end;

%mend;

%appnd(DEC2010);

Super User
Posts: 17,785

Re: date Macro

This seems incredibly complicated. What are you trying to do, explained preferably in words?

The code I ran generated the following, which seems to match what you've stated you want above.

Timmy wrote:

Hi Reeza,

Sorry Reeza i missed the semi colon which i have added.

My problem is i don't want the order of the date.

I want it the other way round like this below

But i want it to start like this

01DEC2010 30NOV2010

02DEC2010 01DEC2010

03DEC2010 02DEC2010

----

Please help

Timmy

01DEC2010 30NOV2010

02DEC2010 01DEC2010

03DEC2010 02DEC2010

04DEC2010 03DEC2010

05DEC2010 04DEC2010

06DEC2010 05DEC2010

07DEC2010 06DEC2010

08DEC2010 07DEC2010

09DEC2010 08DEC2010

10DEC2010 09DEC2010

11DEC2010 10DEC2010

12DEC2010 11DEC2010

13DEC2010 12DEC2010

14DEC2010 13DEC2010

15DEC2010 14DEC2010

16DEC2010 15DEC2010

17DEC2010 16DEC2010

18DEC2010 17DEC2010

19DEC2010 18DEC2010

20DEC2010 19DEC2010

21DEC2010 20DEC2010

22DEC2010 21DEC2010

23DEC2010 22DEC2010

24DEC2010 23DEC2010

25DEC2010 24DEC2010

26DEC2010 25DEC2010

27DEC2010 26DEC2010

28DEC2010 27DEC2010

29DEC2010 28DEC2010

30DEC2010 29DEC2010

31DEC2010 30DEC2010

Occasional Contributor
Posts: 8

Re: date Macro

HI Reeza,

That is the result i want. can you give me code.

regards

Solution
‎05-16-2014 01:41 PM
Super User
Posts: 17,785

Re: date Macro

See 4 posts above.

Occasional Contributor
Posts: 8

Re: date Macro

Thanks Reeza,

I am very greatful.

Kind regards

Occasional Contributor
Posts: 8

Re: date Macro

I am trying to read a data with date

from 01JAN2010 to 31DEC2010

in that order and not 31DEC2010 to 01JAN2010. as my macro is currently doing

☑ This topic is SOLVED.

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

Discussion stats
  • 8 replies
  • 330 views
  • 0 likes
  • 2 in conversation