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

Hi all, 

I am struggling to fix this bit of code . Could someone help me please ?

Many thanks in advance.

%let today=%sysfunc(today());
%let currdt=%sysfunc(datetime());
data _null_;

date2=intnx("month",&today.,-1,'end');
put date2=;
call symputx('DATE2',put(&date2. ,date9.));
%put DATE2=&date2.;

month_id = intck('month','01jan1990'd,today());
put month_id=;
call symputx('month_id',month_id);
%put month_id=&month_id.;

run;
LOG FILE:

23         GOPTIONS ACCESSIBLE;
24         
25         
26         %let today=%sysfunc(today());
27         %let currdt=%sysfunc(datetime());
28         data _null_;
29         
30         date2=intnx("month",&today.,-1,'end');
31         put date2=;
32         call symputx('DATE2',put(&date2. ,date9.));
NOTE: Line generated by the macro variable "DATE2".
32         31JAN2020
             _______
             22
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, <, <=, <>, =, >, ><, >=, AND, EQ, GE, GT, IN, 
              LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, ^=, |, ||, ~=.  

33         %put DATE2=&date2.;
DATE2=31JAN2020
34         
35         month_id = intck('month','01jan1990'd,today());
36         put month_id=;
37         call symputx('month_id',month_id);
38         %put month_id=&month_id.;
month_id=361
39         
40         run;
1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Take care of proper naming of variables in the data step, and of macro timing. The data step needs to RUN to populate the macro variables, so you must not use %put IN the data step:

%let today=%sysfunc(today());
%let currdt=%sysfunc(datetime());

data _null_;
date2=intnx("month",&today.,-1,'end');
put date2=;
call symputx('DATE2',put(date2 ,date9.));
month_id = intck('month','01jan1990'd,today());
put month_id=;
call symputx('month_id',month_id);
run;

%put &=date2;
%put &=month_id;

View solution in original post

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

date2 is not a macro variable

 

%let today=%sysfunc(today());
%let currdt=%sysfunc(datetime());
data _null_;

date2=intnx("month",&today.,-1,'end');
put date2=;
call symputx('DATE2',put(date2 ,date9.));
%put DATE2=&date2.;

month_id = intck('month','01jan1990'd,today());
put month_id=;
call symputx('month_id',month_id);

put month_id=&month_id.;

run;
Kurt_Bremser
Super User

Take care of proper naming of variables in the data step, and of macro timing. The data step needs to RUN to populate the macro variables, so you must not use %put IN the data step:

%let today=%sysfunc(today());
%let currdt=%sysfunc(datetime());

data _null_;
date2=intnx("month",&today.,-1,'end');
put date2=;
call symputx('DATE2',put(date2 ,date9.));
month_id = intck('month','01jan1990'd,today());
put month_id=;
call symputx('month_id',month_id);
run;

%put &=date2;
%put &=month_id;
ed_sas_member
Meteorite | Level 14

Hi @jorquec 

 

Another way to do this:

%let today=%sysfunc(today());
%let currdt=%sysfunc(datetime());
%let date= %sysfunc(intnx(month,&today., -1,e),date9.);
%let month_id= %sysfunc(intck(month,'01jan1990'd,&today.));

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 763 views
  • 7 likes
  • 4 in conversation