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

Hi there,

 

I have the below code that needs to run for each month/year/quartely end dates..

 

data a;
set summary_A (where=( mdate= input(compress("&curr_date."),10.)));
rename total_Tce = Cur_TCE;
rename weighted_PD = Cur_weightedPD;
rename wavgPD = Cur_wavgPD;
run;
data b;
set summary_A1 (where=( mdate= input(compress("&last_yr_date."),10.)));
rename total_Tce = Pre_TCE;
rename weighted_PD = Pre_weightedPD;
rename wavgPD = Pre_wavgPD;
run;

More calaculations based on above variables...However i wanted to put in a single macro to call for all dates like below
but its not working

%macro x(dat,time,var1);
data &dat;
set summary_ANZSIC (where=( mdate= input(compress("&time."),10.)));
rename total_Tce = &var1_TCE;
rename weighted_PD = &var1_weightedPD;
rename wavgPD = &var1_wavgPD;
run;
%mend;
%x(a1,&curr_date.,currm);
%x(a2,&prev_date. ,prevrm);
%x(a3,&last_yr_date.,lasty);
%x(a4,&firstq.,firstq);
%x(a5,&secq.,secq);
%x(a6,&thirdq.,thirdq);
%x(a7,&fourthq.,fourthq);

 

Any help much appreciated..thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Several errors here:

%macro x(dat,time,var1);
data &dat;
set summary_ANZSIC (where=(mdate = input(compress("&time"),date9.)));
/* use the date9. format to get a SAS date value, the log reveals that curr_date comes in that format */
/* I'd rather do this anyway: */
set summary_ANZSIC (where=(mdate = "&time"d));
rename total_Tce = &var1._TCE;
rename weighted_PD = &var1._weightedPD;
rename wavgPD = &var1._wavgPD;
/* in the previous 3 lines, terminate the macrovar name with a dot */
run;
%mend;
%x(a1,&curr_date,curr);
/* don't use quotes around the date, as you already use quotes in the data step inside the macro */

View solution in original post

5 REPLIES 5
Astounding
PROC Star

In your macro calls, you add a dot:

 

&curr_date. instead of &curr_date

&prev_date. instead of &prev_date

&fourthq. instead of &fourthq

 

Do you have any idea why you do that and why you would use a dot?  There are several places in your macro where a dot is needed, but isn't there.

 

For more help than that, you might have to say more than "it's not working".  What type of errors are you getting?  What needs to be fixed?  You may need to run the macro with OPTIONS MPRINT turned on, and post the log.

BaalaRaaji
Quartz | Level 8

If i remove dot..it still having errors...

not able to reslove the macro variable &time ...

 

check below log..

 

GOPTIONS ACCESSIBLE;
29 %macro x(dat,time,var1);
30 data &dat;
31 set summary_ANZSIC (where=( mdate= input(compress("&time"),10.)));
32 rename total_Tce = &var1_TCE;
33 rename weighted_PD = &var1_weightedPD;
34 rename wavgPD = &var1_wavgPD;
35 run;
36 %mend;
37 %x(a1,"&curr_date",curr);
NOTE 138-205: Line generated by the macro variable "TIME".
37 ""31MAR2018"
__
49
__
22
76
NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS release. Inserting white space
between a quoted string and the succeeding identifier is recommended.

ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, ), *, **, +, ',', -, /, <, <=, <>, =, >, >=, ?, AND, BETWEEN,
CONTAINS, EQ, GE, GT, IN, IS, LE, LIKE, LT, NE, NOT, NOTIN, OR, ^, ^=, |, ||, ~, ~=.

ERROR 76-322: Syntax error, statement will be ignored.

22: LINE and COLUMN cannot be determined.
NOTE 242-205: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where the error has occurred.
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, ;, CUROBS, END, INDSNAME, KEY, KEYRESET, KEYS,
NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.
200: LINE and COLUMN cannot be determined.
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where the error has occurred.
ERROR 200-322: The symbol is not recognized and will be ignored.
2 The SAS System 10:30 Tuesday, May 15, 2018

22: LINE and COLUMN cannot be determined.
NOTE 242-205: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where the error has occurred.
ERROR 22-322: Expecting a name.
200: LINE and COLUMN cannot be determined.
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where the error has occurred.
ERROR 200-322: The symbol is not recognized and will be ignored.
22: LINE and COLUMN cannot be determined.
NOTE 242-205: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where the error has occurred.
ERROR 22-322: Expecting a name.
200: LINE and COLUMN cannot be determined.
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where the error has occurred.
ERROR 200-322: The symbol is not recognized and will be ignored.
22: LINE and COLUMN cannot be determined.
NOTE 242-205: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where the error has occurred.
ERROR 22-322: Expecting a name.
200: LINE and COLUMN cannot be determined.
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where the error has occurred.
ERROR 200-322: The symbol is not recognized and will be ignored.
ERROR: Syntax error while parsing WHERE clause.

Kurt_Bremser
Super User

Several errors here:

%macro x(dat,time,var1);
data &dat;
set summary_ANZSIC (where=(mdate = input(compress("&time"),date9.)));
/* use the date9. format to get a SAS date value, the log reveals that curr_date comes in that format */
/* I'd rather do this anyway: */
set summary_ANZSIC (where=(mdate = "&time"d));
rename total_Tce = &var1._TCE;
rename weighted_PD = &var1._weightedPD;
rename wavgPD = &var1._wavgPD;
/* in the previous 3 lines, terminate the macrovar name with a dot */
run;
%mend;
%x(a1,&curr_date,curr);
/* don't use quotes around the date, as you already use quotes in the data step inside the macro */
BaalaRaaji
Quartz | Level 8

%macro x(test,time,var1);
data &test.;
set summary_ANZSIC;
where mdate= input(compress("&time."),10.);
rename total_Tce = &var1._TCE;
rename weighted_PD = &var1._weightedPD;
rename wavgPD = &var1._wavgPD;
run;
%mend;
%x(a1,&curr_date,curr);
%x(a2,&last_yr_date,prev);

 

updated the code as above..

Working now..thanks everyone..

ballardw
Super User

@BaalaRaaji wrote:

%macro x(test,time,var1);
data &test.;
set summary_ANZSIC;
where mdate= input(compress("&time."),10.);
rename total_Tce = &var1._TCE;
rename weighted_PD = &var1._weightedPD;
rename wavgPD = &var1._wavgPD;
run;
%mend;
%x(a1,&curr_date,curr);
%x(a2,&last_yr_date,prev);

 

updated the code as above..

Working now..thanks everyone..


Be aware that creating new variable names with fixed suffixes means that you must be careful not to pass a variable name such that the "new" name is not truncated. Adding "_weightedPD", 11 characters, to a variable name means that if the length of &var1 ever exceeds 21 characters you will have a new variable name greater than the allowed 32 characters and the result will be truncated. So later reference to &var1._unweightedPD may generate errors as the variable won't have that name.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1170 views
  • 1 like
  • 4 in conversation