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

Hi,

I am trying to run the below code:

%macro temp2;
/*proc reg data=REPAM_DIF_EXTEND_ECONS1 outest=test plots=none;*/
/*m0: model IO_high_newhpi=&repam_dif_econs.	/SBC rsquare adjrsq dw vif;*/
%put &=model_vars.
	&=repam_dif_econs.;
%do i=1 %to %sysfunc(countw(&model_vars.,%str( )));
	%put &=i.;
	%let var_remove=%str();
	%do j=4 %to 0 %by -1;
		%put &=j.;
			%let var_remove=%sysfunc(catx(%str( ),&var_remove.,%scan(&repam_dif_econs.,%eval(5*&i.+&j.))));
				%put &=var_remove.;
/*				m%eval(5*&i.-&j.): model IO_high_newhpi=%sysfunc(transtrn(&repam_dif_econs.,&var_remove.,%str()))/ SBC rsquare adjrsq dw vif;*/
	%end;
%end;
/*run;*/
/*quit;*/
%mend temp2;
%temp2;

It produces the log:

 

25         GOPTIONS ACCESSIBLE;
26         %macro temp2;
27         /*proc reg data=REPAM_DIF_EXTEND_ECONS1 outest=test plots=none;*/
28         /*m0: model IO_high_newhpi=&repam_dif_econs.	/SBC rsquare adjrsq dw vif;*/
29         %put &=model_vars.
30         	&=repam_dif_econs.;
31         %do i=1 %to %sysfunc(countw(&model_vars.,%str( )));
32         	%put &=i.;
33         	%let var_remove=%str();
34         	%do j=4 %to 0 %by -1;
35         		%put &=j.;
36         			%let var_remove=%sysfunc(catx(%str( ),&var_remove.,%scan(&repam_dif_econs.,%eval(5*&i.+&j.))));
37         				%put &=var_remove.;
38         /*				m%eval(5*&i.-&j.): model IO_high_newhpi=%sysfunc(transtrn(&repam_dif_econs.,&var_remove.,%str()))/ SBC rsquare
38       ! adjrsq dw vif;*/
39         	%end;
40         %end;
41         /*run;*/
42         /*quit;*/
43         %mend temp2;
44         %temp2;
MODEL_VARS=HPIM_NSA_INDEX_NEWHPIb_yoy_l_11 ILO_UE_Qb_yoy_l_11 MIGb_bob_l_12 TOT_HH_DTI_EX_SLb_l2  
REPAM_DIF_ECONS=HPIM_NSA_INDEX_NEWHPIb_yoy_l_11 ILO_UE_Qb_yoy_l_11 MIGb_bob_l_12 TOT_HH_DTI_EX_SLb_l2 
HPIM_NSA_INDEX_NEWHPIb_yoy_d_l11 HPIM_NSA_INDEX_NEWHPIb_yoy_d_l12 HPIM_NSA_INDEX_NEWHPIb_yoy_d_l13 HPIM_NSA_INDEX_NEWHPIb_yoy_d_l14 
HPIM_NSA_INDEX_NEWHPIb_yoy_d_l15 ILO_UE_Qb_yoy_d_l11 ILO_UE_Qb_yoy_d_l12 ILO_UE_Qb_yoy_d_l13 ILO_UE_Qb_yoy_d_l14 
ILO_UE_Qb_yoy_d_l15 MIGb_bob_d_l12 MIGb_bob_d_l13 MIGb_bob_d_l14 MIGb_bob_d_l15 MIGb_bob_d_l16 TOT_HH_DTI_EX_SLb_d_l_2 
TOT_HH_DTI_EX_SLb_d_l_3 TOT_HH_DTI_EX_SLb_d_l_4 TOT_HH_DTI_EX_SLb_d_l_5 TOT_HH_DTI_EX_SLb_d_l_6
I=1
J=4
ERROR: %SYSEVALF function has no expression to evaluate.
VAR_REMOVE=HPIM_NSA_INDEX_NEWHPIb_yoy_d_l15
J=3
2                                                          The SAS System                              10:41 Friday, August 13, 2021

VAR_REMOVE=HPIM_NSA_INDEX_NEWHPIb_yoy_d_l15 HPIM_NSA_INDEX_NEWHPIb_yoy_d_l14
J=2
VAR_REMOVE=HPIM_NSA_INDEX_NEWHPIb_yoy_d_l15 HPIM_NSA_INDEX_NEWHPIb_yoy_d_l14 HPIM_NSA_INDEX_NEWHPIb_yoy_d_l13
J=1
VAR_REMOVE=HPIM_NSA_INDEX_NEWHPIb_yoy_d_l15 HPIM_NSA_INDEX_NEWHPIb_yoy_d_l14 HPIM_NSA_INDEX_NEWHPIb_yoy_d_l13 
HPIM_NSA_INDEX_NEWHPIb_yoy_d_l12
J=0
VAR_REMOVE=HPIM_NSA_INDEX_NEWHPIb_yoy_d_l15 HPIM_NSA_INDEX_NEWHPIb_yoy_d_l14 HPIM_NSA_INDEX_NEWHPIb_yoy_d_l13 
HPIM_NSA_INDEX_NEWHPIb_yoy_d_l12 HPIM_NSA_INDEX_NEWHPIb_yoy_d_l11
I=2
J=4
ERROR: %SYSEVALF function has no expression to evaluate.
VAR_REMOVE=ILO_UE_Qb_yoy_d_l15
J=3
VAR_REMOVE=ILO_UE_Qb_yoy_d_l15 ILO_UE_Qb_yoy_d_l14
J=2
VAR_REMOVE=ILO_UE_Qb_yoy_d_l15 ILO_UE_Qb_yoy_d_l14 ILO_UE_Qb_yoy_d_l13
J=1
VAR_REMOVE=ILO_UE_Qb_yoy_d_l15 ILO_UE_Qb_yoy_d_l14 ILO_UE_Qb_yoy_d_l13 ILO_UE_Qb_yoy_d_l12
J=0
VAR_REMOVE=ILO_UE_Qb_yoy_d_l15 ILO_UE_Qb_yoy_d_l14 ILO_UE_Qb_yoy_d_l13 ILO_UE_Qb_yoy_d_l12 ILO_UE_Qb_yoy_d_l11
I=3
J=4

 

As seen in the log, the code is generating the desired output, but it is also generating the error in the mentioned in the title, in spite of the absence of a %sysevalf function. I previously had a %sysevalf function in the code, which was suggested when trying to troubleshoot some other now resolved issue, and the error first arose when I ran it then. However, since returning to using the %eval() function, the error is still generated. I have restarted the session, tried the code in a new macro, tried the macro in a new program in the sas project, and tried running the magic string, but the error still persists. I have read on some similar threads that such an error can arise from the macro language trying to parse %str( ) in %sysfunc(catx( )) or %scan( ), but I need the string to be delimited %str( ) for my purposes. I don't know how to fix this, so any help would be greatly appreciated.

Cheers,

Douglas

1 ACCEPTED SOLUTION

Accepted Solutions
dh735
Fluorite | Level 6

For the benefit of anybody reading along, I just removed the catx step to concatenate strings, which you seemingly do not need when working with macros (I guess because it just reads everything as text). This solution tallies up with other post pertaining to %sysevalf errors when using %sysfunc(catx( )) on macro strings. 👍

%macro temp2;
proc reg data=REPAM_DIF_EXTEND_ECONS1 outest=test plots=none;
m0: model IO_high_newhpi=&repam_dif_econs.	/SBC rsquare adjrsq dw vif;
/*%put &=model_vars.*/
/*	&=repam_dif_econs.;*/
%do i=1 %to %sysfunc(countw(&model_vars.,%str( )));
	%put &=i.;
	%let var_remove=%str();
	%do j=0 %to 4;
		%put &=j.;

			%let var_remove=%sysfunc(strip(&var_remove. %scan(&repam_dif_econs.,%eval(5*&i.+&j.),%str( ))));
				%put &=var_remove.;
				m%eval(5*&i.-&j.): model IO_high_newhpi=%sysfunc(transtrn(&repam_dif_econs.,&var_remove.,%str()))/ SBC rsquare adjrsq dw vif;
	%end;
%end;
run;
quit;
%mend temp2;
%temp2;

 

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

Use this command to provide macro debugging information:

 

options symbolgen mlogic mprint;

 

Then re-run the code, and examine the log.

--
Paige Miller
dh735
Fluorite | Level 6

For the benefit of anybody reading along, I just removed the catx step to concatenate strings, which you seemingly do not need when working with macros (I guess because it just reads everything as text). This solution tallies up with other post pertaining to %sysevalf errors when using %sysfunc(catx( )) on macro strings. 👍

%macro temp2;
proc reg data=REPAM_DIF_EXTEND_ECONS1 outest=test plots=none;
m0: model IO_high_newhpi=&repam_dif_econs.	/SBC rsquare adjrsq dw vif;
/*%put &=model_vars.*/
/*	&=repam_dif_econs.;*/
%do i=1 %to %sysfunc(countw(&model_vars.,%str( )));
	%put &=i.;
	%let var_remove=%str();
	%do j=0 %to 4;
		%put &=j.;

			%let var_remove=%sysfunc(strip(&var_remove. %scan(&repam_dif_econs.,%eval(5*&i.+&j.),%str( ))));
				%put &=var_remove.;
				m%eval(5*&i.-&j.): model IO_high_newhpi=%sysfunc(transtrn(&repam_dif_econs.,&var_remove.,%str()))/ SBC rsquare adjrsq dw vif;
	%end;
%end;
run;
quit;
%mend temp2;
%temp2;

 

PaigeMiller
Diamond | Level 26

For the benefit of anyone reading along, @dh735 please explain what you changed and why this code is now marked correct.

--
Paige Miller
Tom
Super User Tom
Super User

I don't know if it has anything to do with your problem, but why would you write code like this?

%let var_remove=%sysfunc(catx(%str( ),&var_remove.,%scan(&repam_dif_econs.,%eval(5*&i.+&j.))));

There is no need to use CATX() to add a space between values.  Just type the space!

Plus %SCAN() knows how to call %EVAL() (%sysfunc() does also).

%let var_remove=&var_remove. %scan(&repam_dif_econs.,5*&i.+&j.);
dh735
Fluorite | Level 6

Hi Tom,

  1. "why would you write code like this?": Because I don't know any better 😬
  2. "%Scan knows how to call %Eval": I never knew that about %scan, thank you!

Cheers,

Douglas

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 5 replies
  • 2293 views
  • 3 likes
  • 3 in conversation