DATA Step, Macro, Functions and more

Macro dates

Accepted Solution Solved
Reply
Highlighted
Contributor
Posts: 35
Accepted Solution

Macro dates

[ Edited ]

I am trying to create two macro dates using enterprise guide 7.1 SAS version 9.4. The first date is based off of today's date and works fine. alpha is yesterday.  The second date is suppose to be the same day in the prior month from alpha.  So if today is June 13, alpha is jun 12 and beta would be may 12.

data _null_;

call symputx('alpha', PUT(intnx('DAY',%SYSFUNC(today()),-1), date9.)); * yesterday;

call symputx('beta', PUT(intnx('MONTH',%SYSFUNC(&alpha,-1), date9.)); * last month same day;

RUN;


Accepted Solutions
Solution
a week ago
PROC Star
Posts: 1,603

Re: Macro dates

Posted in reply to novinosrin

Corrected

 

data _null_;

call symputx('alpha', PUT(intnx('DAY',today(),-1), date9.)); * yesterday;

call symputx('beta', PUT(intnx('MONTH',today()-1,-1,'s'), date9.)); * last month same day;

RUN;

%put α

%put β

View solution in original post


All Replies
PROC Star
Posts: 1,603

Re: Macro dates

data _null_;

call symputx('alpha', PUT(intnx('DAY',today(),-1), date9.)); * yesterday;

call symputx('beta', PUT(intnx('MONTH',today(),-1,'s'), date9.)); * last month same day;

RUN;

%put α

%put β
Solution
a week ago
PROC Star
Posts: 1,603

Re: Macro dates

Posted in reply to novinosrin

Corrected

 

data _null_;

call symputx('alpha', PUT(intnx('DAY',today(),-1), date9.)); * yesterday;

call symputx('beta', PUT(intnx('MONTH',today()-1,-1,'s'), date9.)); * last month same day;

RUN;

%put α

%put β
Contributor
Posts: 35

Re: Macro dates

Posted in reply to novinosrin

NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR

24

25 GOPTIONS ACCESSIBLE;

26 data _null_;

27 call symputx('alpha', PUT(intnx('DAY',today(),-1), date9.)); * yesterday;

28 call symputx('beta', PUT(intnx('MONTH',today(),-1,-1,'s'), date9.)); * yesterday;

29 RUN;

NOTE: Numeric values have been converted to character values at the places given by: (Line)Smiley SadColumn).

28:51

NOTE: Argument 5 to function INTNX('MONTH',21348,-1,' -1','s') at line 28 column 26 is invalid.

_ERROR_=1 _N_=1

NOTE: Mathematical operations could not be performed at the following places. The results of the operations have been set to

missing values.

Each place is given by: (Number of times) at (Line)Smiley SadColumn).

1 at 28:26

NOTE: DATA statement used (Total process time):

real time 0.01 seconds

cpu time 0.00 seconds

PROC Star
Posts: 1,603

Re: Macro dates

[ Edited ]

@pangea17 you didn't quite exactly copy paste my code 

 

there is a difference in the 2nd call symputx with yours and mine. Kindly review thoroughly. Please and thank you

 

mine:  call symputx('beta', PUT(intnx('MONTH',today()-1,-1,'s'), date9.)); * last month same day;

 

 

yours:  call symputx('beta', PUT(intnx('MONTH',today(),-1,-1,'s'), date9.)); * yesterday;

Contributor
Posts: 35

Re: Macro dates

Posted in reply to novinosrin

That did work great!  Thank you.

PROC Star
Posts: 1,603

Re: Macro dates

I'm glad. Have fun!

Super User
Posts: 9,925

Re: Macro dates


@pangea17 wrote:

I am trying to create two macro dates using enterprise guide 7.1 SAS version 9.4. The first date is based off of today's date and works fine. alpha is yesterday.  The second date is suppose to be the same day in the prior month from alpha.  So if today is June 13, alpha is jun 12 and beta would be may 12.

data _null_;

call symputx('alpha', PUT(intnx('DAY',%SYSFUNC(today()),-1), date9.)); * yesterday;

call symputx('beta', PUT(intnx('MONTH',%SYSFUNC(&alpha,-1), date9.)); * last month same day;

RUN;


In your code, the macro preprocessor tries to resolve &alpha before it is created.

%sysfunc only accepts a data step function call as its argument, and not a macro variable.

A previous day is calculated best by simply subtracting 1 from a date.

data _null_;
call symputx('alpha', put(today()-1, date9.)); * yesterday;
call symputx('beta', put(intnx('month',today()-1,-1), date9.)); * last month same day;
run;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
☑ This topic is solved.

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

Discussion stats
  • 7 replies
  • 97 views
  • 0 likes
  • 3 in conversation