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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

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

7 REPLIES 7
novinosrin
Tourmaline | Level 20
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 β
novinosrin
Tourmaline | Level 20

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 β
pangea17
Quartz | Level 8

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):(Column).

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):(Column).

1 at 28:26

NOTE: DATA statement used (Total process time):

real time 0.01 seconds

cpu time 0.00 seconds

novinosrin
Tourmaline | Level 20

@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;

pangea17
Quartz | Level 8

That did work great!  Thank you.

novinosrin
Tourmaline | Level 20

I'm glad. Have fun!

Kurt_Bremser
Super User

@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;

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
  • 1444 views
  • 0 likes
  • 3 in conversation