I am trying to perform an action based on whether a variable value is equal to some text inside a macro but I am getting the following message:
"A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:
&MyToken EQ 1 and &Mytitle3 EQ "All-Sources Protein Foods""
This is the piece of code I use:
%if &MyToken EQ 1
and &Mytitle3 EQ "All-Sources Protein Foods"
%then %do ;
Any suggestion why a numeric value is required?
Thanks in advance for any help you can give.
Erik
SYMBOLGEN: Macro variable MYTOKEN resolves to 1 SYMBOLGEN: Macro variable MYTITLE3 resolves to All-Sources Protein Foods ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: &MyToken EQ 1 and &Mytitle3 EQ "All-Sources Protein Foods"
&MYTITLE3 has value All-Sources Protein Foods which does not equal "All-Sources Protein Foods". Can you see why?
In addition, the error message probably arises because when the macro processor sees MYTITLE3 whose value starts with All-Sources, it interprets the dash as subtraction, which I'm sure is not what you meant. It wants numbers for subtraction and you have provided text strings for subtraction.
So I think the code you want would be
%if &MyToken EQ 1 and %quote(&Mytitle3) EQ %str(All-Sources Protein Foods) %then ...
which I haven't really tested, but you can test easily.
Side issue: I said "Please show us the ENTIRE log for this DATA step or PROC" which should have probably read "Please show us the ENTIRE log for this DATA step or PROC or macro". We don't need the hundreds of lines before the execution of the macro, PROC or DATA step.
For us to provide the best help, never show us a partial LOG. Please show us the ENTIRE log for this DATA step or PROC. Copy the log as text and paste it into the window that appears when you click on the </> icon.
Also, before you run the code, please turn on macro debugging options.
options symbolgen mlogic;
Then run the code again and show us the log as explained.
There you go!
1 The SAS System 10:09 Tuesday, August 23, 2022 1 ;*';*";*/;quit;run; 2 OPTIONS PAGENO=MIN; 3 %LET _CLIENTTASKLABEL='Question 2 Draft 5'; 4 %LET _CLIENTPROCESSFLOWNAME='Process Flow'; 5 %LET _CLIENTPROJECTPATH=''; 6 %LET _CLIENTPROJECTPATHHOST=''; 7 %LET _CLIENTPROJECTNAME=''; 8 %LET _SASPROGRAMFILE='/appdata/sasusers/Common/HPFB_DGPSA/onpp/29-2015 CCHS Nutrition Analysis/Code/Question 2 Draft 8 ! 5.sas'; 9 %LET _SASPROGRAMFILEHOST='sinpappsas-05.hc-sc.gc.ca'; 10 11 ODS _ALL_ CLOSE; 12 OPTIONS DEV=PNG; 13 FILENAME EGSR TEMP; 14 ODS tagsets.sasreport13(ID=EGSR) FILE=EGSR 15 STYLE=HTMLBlue 16 STYLESHEET=(URL="file:///C:/Program%20Files/SASHome2/SASEnterpriseGuide/7.1/Styles/HTMLBlue.css") 17 NOGTITLE 18 NOGFOOTNOTE 19 GPATH=&sasworklocation SYMBOLGEN: Macro variable SASWORKLOCATION resolves to "/grid_work/SAS_work62A30000350C_SINPAPPSAS-05.hc-sc.gc.ca/SAS_workD4C60000350C_SINPAPPSAS-05.hc-sc.gc.ca/" 20 ENCODING=UTF8 21 options(rolap="on") 22 ; NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR 23 24 * Macro rebuild ; 25 26 %macro BigMac( MyToken=, 27 Mytitle2=, 28 Mytitle3=, 29 Mytitle4=, 30 MyDomn =, 31 MyBoot =, 32 Myfmt =, 33 MyDRI =, 34 MyDRIMat=, 35 MyProteinMat= ) ; 36 37 %if &MyToken EQ 1 38 and &Mytitle3 EQ "All-Sources Protein Foods" 39 40 %then %do ; 41 42 * **************************************************** ; 43 * Mean amount consumed per respondent Per Tier in grams ; 44 * **************************************************** ; 45 ODS EXCLUDE SUMMARY 46 STATISTICS 47 VARIANCEESTIMATION ; 48 49 proc surveymeans ZeData.SumAmtPerASPGroupperRespDRIwB /*varmethod=brr*/ NOBS MEAN STDERR CLM CV plots = none varheader = 49 ! LABEL ; 50 51 title1 "Mean Amount Consumed (g) Per Food Category & Tier" ; 52 title2 "&Mytitle2" ; 53 title3 "&Mytitle3" ; 2 The SAS System 10:09 Tuesday, August 23, 2022 54 title4 "&Mytitle4" ; 55 56 var AmtT1ASPCat1 57 var AmtT2ASPCat1 58 var AmtT3ASPCat1 59 60 var AmtT1ASPCat2 61 var AmtT2ASPCat2 62 var AmtT3ASPCat2 63 64 var AmtT1ASPCat3 65 var AmtT2ASPCat3 66 var AmtT3ASPCat3 67 68 var AmtT1ASPCat4 69 var AmtT2ASPCat4 70 var AmtT3ASPCat4 71 72 var AmtT1ASPCat5 73 var AmtT2ASPCat5 74 var AmtT3ASPCat5 75 76 var AmtAllTASPCat1 77 var AmtAllTASPCat2 78 var AmtAllTASPCat3 79 var AmtAllTASPCat4 80 var AmtAllTASPCat5 81 82 var AmtAllTAllASPCat 83 84 domain &MyDomn ; 85 86 weight wts_s ; 87 repweight bsw1-bsw&MyBoot ; 88 89 &Myfmt &MyDRI &MyDRIMat ; 90 91 run ; 92 %end ; 93 94 %else %if &MyToken EQ 1 95 and &Mytitle3 EQ "Plant vs Animal-Based Protein Food" 96 %then %do ; 97 98 ODS EXCLUDE SUMMARY 99 STATISTICS 100 VARIANCEESTIMATION ; 101 102 proc surveymeans ZeData.SumAmtPerPBABGroupperRespDRIwB /*varmethod=brr*/ NOBS MEAN STDERR CLM CV plots = none varheader 102 ! = LABEL ; 103 104 title1 "Mean Amount Consumed (g) Per Food Category & Tier" ; 105 title2 "&Mytitle2" ; 106 title3 "&Mytitle3" ; 107 title4 "&Mytitle4" ; 108 109 var AmtT1PBABCat1 110 var AmtT2PBABCat1 3 The SAS System 10:09 Tuesday, August 23, 2022 111 var AmtT3PBABCat1 112 113 var AmtT1PBABCat2 114 var AmtT2PBABCat2 115 var AmtT3PBABCat2 116 117 var AmtT1PBABCat3 118 var AmtT2PBABCat3 119 var AmtT3PBABCat3 120 121 var AmtT1PBABCat4 122 var AmtT2PBABCat4 123 var AmtT3PBABCat4 124 125 var AmtT1PBABCat5 126 var AmtT2PBABCat5 127 var AmtT3PBABCat5 128 129 var AmtAllTPBABCat1 130 var AmtAllTPBABCat2 131 var AmtAllTPBABCat3 132 var AmtAllTPBABCat4 133 var AmtAllTPBABCat5 134 135 var AmtAllTAllPBABCat 136 137 domain &MyDomn ; 138 139 weight wts_s ; 140 repweight bsw1-bsw&MyBoot ; 141 142 &Myfmt &MyDRI &MyDRIMat ; 143 144 run ; 145 %end ; 146 147 %mend BigMac ; NOTE: The macro BIGMAC completed compilation without errors. 58 instructions 3208 bytes. 148 149 * * * * * * * * * * * * * * * * * * To call macros ; 150 %macro BiggerMac(Token=,Mytitlethree=,MyPro=,MyBBoot=,) ; 151 152 %BigMac(MyToken=&Token, 153 Mytitle2=All Standard DRI Life Stage Groups, 154 Mytitle3=&Mytitlethree, 155 Mytitle4=&MyBBoot Bootstrap Samples, 156 MyDomn =DHHDDRI, 157 MyBoot =&MyBBoot, 158 Myfmt =, 159 MyDRI =, 160 MyDRIMat=, 161 MyProteinMat=&MyPro ) ; 162 163 164 %BigMac(MyToken=&Token, 165 Mytitle2=Selected DRI Males & Females Combined, 166 Mytitle3=&Mytitlethree, 4 The SAS System 10:09 Tuesday, August 23, 2022 167 Mytitle4=&MyBBoot Bootstrap Samples, 168 MyDomn =DHHDDRI, 169 MyBoot =&MyBBoot, 170 Myfmt =format, 171 MyDRI =DHHDDRI, 172 MyDRIMat=DRIs_Combined_F., 173 MyProteinMat=&MyPro ) ; 174 175 %mend BiggerMac ; NOTE: The macro BIGGERMAC completed compilation without errors. 19 instructions 920 bytes. 176 177 %macro BiggestMac ; 178 179 %do T = 1 %to 1 ; 180 181 %if &T EQ 1 %then %let MyName = Mean amount consumed ; 182 %if &T EQ 2 %then %let MyName = Mean number of RAs ; 183 %if &T EQ 3 %then %let MyName = Mean ratio of Tiers ; 184 %if &T EQ 4 %then %let MyName = Mean amount of HB ; 185 %if &T EQ 5 %then %let MyName = Mean Number of RAs of HB ; 186 %if &T EQ 6 %then %let MyName = Mean amount of HBSP ; 187 %if &T EQ 7 %then %let MyName = Mean Number of RAs of HBSP ; 188 %if &T EQ 8 %then %let MyName = Mean amount of Sugary Drinks ; 189 %if &T EQ 9 %then %let MyName = Mean Number of RA of Sugary Drinks ; 190 191 ods excel file="/appdata/HPFB_DGPSA/onpp/29-2015 CCHS Nutrition Analysis/&MyName..xlsx" ; 192 ods excel options( embedded_titles = "yes" ) ; 193 ods noproctitle ; 194 195 %if &T LE 3 %then 196 %do ; 197 ods excel options( sheet_name = "All Sources Protein" 198 sheet_interval = "none" ) ; 199 %end ; 200 201 %if &T IN (4,5) %then 202 %do ; 203 ods excel options( sheet_name = "Healthy Bev" 204 sheet_interval = "none" ) ; 205 %end ; 206 207 %if &T IN (6,7) %then 208 %do ; 209 ods excel options( sheet_name = "Healthy Bev Source of Pro" 210 sheet_interval = "none" ) ; 211 %end ; 212 213 %if &T IN (8,9) %then 214 %do ; 215 ods excel options( sheet_name = "Sugary Drinks" 216 sheet_interval = "none" ) ; 217 %end ; 218 219 %BiggerMac( Token=&T, 220 Mytitlethree=All-Sources Protein Foods, 221 MyBBoot=2) ; 222 5 The SAS System 10:09 Tuesday, August 23, 2022 223 %if &T LE 3 %then 224 %do ; 225 ods excel options( sheet_name="Plant vs Animal Protein" 226 sheet_interval = "now" ) ; 227 228 %BiggerMac( Token=&T, 229 Mytitlethree=Plant vs Animal-Based Protein Food, 230 MyBBoot=2) ; 231 %end ; 232 233 ods excel close ; 234 235 %end ; 236 237 %mend BiggestMac ; NOTE: The macro BIGGESTMAC completed compilation without errors. 137 instructions 3696 bytes. 238 239 * To call macro ; 240 %BiggestMac ; MLOGIC(BIGGESTMAC): Beginning execution. NOTE: The macro BIGGESTMAC is executing from memory. 137 instructions 3696 bytes. MLOGIC(BIGGESTMAC): %DO loop beginning; index variable T; start value is 1; stop value is 1; by value is 1. SYMBOLGEN: Macro variable T resolves to 1 MLOGIC(BIGGESTMAC): %IF condition &T EQ 1 is TRUE MLOGIC(BIGGESTMAC): %LET (variable name is MYNAME) SYMBOLGEN: Macro variable T resolves to 1 MLOGIC(BIGGESTMAC): %IF condition &T EQ 2 is FALSE SYMBOLGEN: Macro variable T resolves to 1 MLOGIC(BIGGESTMAC): %IF condition &T EQ 3 is FALSE SYMBOLGEN: Macro variable T resolves to 1 MLOGIC(BIGGESTMAC): %IF condition &T EQ 4 is FALSE SYMBOLGEN: Macro variable T resolves to 1 MLOGIC(BIGGESTMAC): %IF condition &T EQ 5 is FALSE SYMBOLGEN: Macro variable T resolves to 1 MLOGIC(BIGGESTMAC): %IF condition &T EQ 6 is FALSE SYMBOLGEN: Macro variable T resolves to 1 MLOGIC(BIGGESTMAC): %IF condition &T EQ 7 is FALSE SYMBOLGEN: Macro variable T resolves to 1 MLOGIC(BIGGESTMAC): %IF condition &T EQ 8 is FALSE SYMBOLGEN: Macro variable T resolves to 1 MLOGIC(BIGGESTMAC): %IF condition &T EQ 9 is FALSE SYMBOLGEN: Macro variable MYNAME resolves to Mean amount consumed MPRINT(BIGGESTMAC): ods excel file="/appdata/HPFB_DGPSA/onpp/29-2015 CCHS Nutrition Analysis/Mean amount consumed.xlsx" ; MPRINT(BIGGESTMAC): ods excel options( embedded_titles = "yes" ) ; MPRINT(BIGGESTMAC): ods noproctitle ; SYMBOLGEN: Macro variable T resolves to 1 MLOGIC(BIGGESTMAC): %IF condition &T LE 3 is TRUE MPRINT(BIGGESTMAC): ods excel options( sheet_name = "All Sources Protein" sheet_interval = "none" ) ; SYMBOLGEN: Macro variable T resolves to 1 MLOGIC(BIGGESTMAC): %IF condition &T IN (4,5) is FALSE SYMBOLGEN: Macro variable T resolves to 1 MLOGIC(BIGGESTMAC): %IF condition &T IN (6,7) is FALSE SYMBOLGEN: Macro variable T resolves to 1 MLOGIC(BIGGESTMAC): %IF condition &T IN (8,9) is FALSE MLOGIC(BIGGERMAC): Beginning execution. NOTE: The macro BIGGERMAC is executing from memory. 6 The SAS System 10:09 Tuesday, August 23, 2022 19 instructions 920 bytes. SYMBOLGEN: Macro variable T resolves to 1 MLOGIC(BIGGERMAC): Parameter TOKEN has value 1 MLOGIC(BIGGERMAC): Parameter MYTITLETHREE has value All-Sources Protein Foods MLOGIC(BIGGERMAC): Parameter MYBBOOT has value 2 MLOGIC(BIGGERMAC): Parameter MYPRO has value MLOGIC(BIGMAC): Beginning execution. NOTE: The macro BIGMAC is executing from memory. 58 instructions 3208 bytes. SYMBOLGEN: Macro variable TOKEN resolves to 1 SYMBOLGEN: Macro variable MYTITLETHREE resolves to All-Sources Protein Foods SYMBOLGEN: Macro variable MYBBOOT resolves to 2 SYMBOLGEN: Macro variable MYBBOOT resolves to 2 SYMBOLGEN: Macro variable MYPRO resolves to MLOGIC(BIGMAC): Parameter MYTOKEN has value 1 MLOGIC(BIGMAC): Parameter MYTITLE2 has value All Standard DRI Life Stage Groups MLOGIC(BIGMAC): Parameter MYTITLE3 has value All-Sources Protein Foods MLOGIC(BIGMAC): Parameter MYTITLE4 has value 2 Bootstrap Samples MLOGIC(BIGMAC): Parameter MYDOMN has value DHHDDRI MLOGIC(BIGMAC): Parameter MYBOOT has value 2 MLOGIC(BIGMAC): Parameter MYFMT has value MLOGIC(BIGMAC): Parameter MYDRI has value MLOGIC(BIGMAC): Parameter MYDRIMAT has value MLOGIC(BIGMAC): Parameter MYPROTEINMAT has value SYMBOLGEN: Macro variable MYTOKEN resolves to 1 SYMBOLGEN: Macro variable MYTITLE3 resolves to All-Sources Protein Foods ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: &MyToken EQ 1 and &Mytitle3 EQ "All-Sources Protein Foods" ERROR: The macro BIGMAC will stop executing. MLOGIC(BIGMAC): Ending execution. MPRINT(BIGGERMAC): ; MLOGIC(BIGMAC): Beginning execution. NOTE: The macro BIGMAC is executing from memory. 58 instructions 3208 bytes. SYMBOLGEN: Macro variable TOKEN resolves to 1 SYMBOLGEN: Macro variable MYTITLETHREE resolves to All-Sources Protein Foods SYMBOLGEN: Macro variable MYBBOOT resolves to 2 SYMBOLGEN: Macro variable MYBBOOT resolves to 2 SYMBOLGEN: Macro variable MYPRO resolves to MLOGIC(BIGMAC): Parameter MYTOKEN has value 1 MLOGIC(BIGMAC): Parameter MYTITLE2 has value Selected DRI Males & Females Combined MLOGIC(BIGMAC): Parameter MYTITLE3 has value All-Sources Protein Foods MLOGIC(BIGMAC): Parameter MYTITLE4 has value 2 Bootstrap Samples MLOGIC(BIGMAC): Parameter MYDOMN has value DHHDDRI MLOGIC(BIGMAC): Parameter MYBOOT has value 2 MLOGIC(BIGMAC): Parameter MYFMT has value format MLOGIC(BIGMAC): Parameter MYDRI has value DHHDDRI MLOGIC(BIGMAC): Parameter MYDRIMAT has value DRIs_Combined_F. MLOGIC(BIGMAC): Parameter MYPROTEINMAT has value SYMBOLGEN: Macro variable MYTOKEN resolves to 1 SYMBOLGEN: Macro variable MYTITLE3 resolves to All-Sources Protein Foods ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: &MyToken EQ 1 and &Mytitle3 EQ "All-Sources Protein Foods" ERROR: The macro BIGMAC will stop executing. MLOGIC(BIGMAC): Ending execution. MPRINT(BIGGERMAC): ; MLOGIC(BIGGERMAC): Ending execution. MPRINT(BIGGESTMAC): ; 7 The SAS System 10:09 Tuesday, August 23, 2022 SYMBOLGEN: Macro variable T resolves to 1 MLOGIC(BIGGESTMAC): %IF condition &T LE 3 is TRUE MPRINT(BIGGESTMAC): ods excel options( sheet_name="Plant vs Animal Protein" sheet_interval = "now" ) ; MLOGIC(BIGGERMAC): Beginning execution. NOTE: The macro BIGGERMAC is executing from memory. 19 instructions 920 bytes. SYMBOLGEN: Macro variable T resolves to 1 MLOGIC(BIGGERMAC): Parameter TOKEN has value 1 MLOGIC(BIGGERMAC): Parameter MYTITLETHREE has value Plant vs Animal-Based Protein Food MLOGIC(BIGGERMAC): Parameter MYBBOOT has value 2 MLOGIC(BIGGERMAC): Parameter MYPRO has value MLOGIC(BIGMAC): Beginning execution. NOTE: The macro BIGMAC is executing from memory. 58 instructions 3208 bytes. SYMBOLGEN: Macro variable TOKEN resolves to 1 SYMBOLGEN: Macro variable MYTITLETHREE resolves to Plant vs Animal-Based Protein Food SYMBOLGEN: Macro variable MYBBOOT resolves to 2 SYMBOLGEN: Macro variable MYBBOOT resolves to 2 SYMBOLGEN: Macro variable MYPRO resolves to MLOGIC(BIGMAC): Parameter MYTOKEN has value 1 MLOGIC(BIGMAC): Parameter MYTITLE2 has value All Standard DRI Life Stage Groups MLOGIC(BIGMAC): Parameter MYTITLE3 has value Plant vs Animal-Based Protein Food MLOGIC(BIGMAC): Parameter MYTITLE4 has value 2 Bootstrap Samples MLOGIC(BIGMAC): Parameter MYDOMN has value DHHDDRI MLOGIC(BIGMAC): Parameter MYBOOT has value 2 MLOGIC(BIGMAC): Parameter MYFMT has value MLOGIC(BIGMAC): Parameter MYDRI has value MLOGIC(BIGMAC): Parameter MYDRIMAT has value MLOGIC(BIGMAC): Parameter MYPROTEINMAT has value SYMBOLGEN: Macro variable MYTOKEN resolves to 1 SYMBOLGEN: Macro variable MYTITLE3 resolves to Plant vs Animal-Based Protein Food ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: &MyToken EQ 1 and &Mytitle3 EQ "All-Sources Protein Foods" ERROR: The macro BIGMAC will stop executing. MLOGIC(BIGMAC): Ending execution. MPRINT(BIGGERMAC): ; MLOGIC(BIGMAC): Beginning execution. NOTE: The macro BIGMAC is executing from memory. 58 instructions 3208 bytes. SYMBOLGEN: Macro variable TOKEN resolves to 1 SYMBOLGEN: Macro variable MYTITLETHREE resolves to Plant vs Animal-Based Protein Food SYMBOLGEN: Macro variable MYBBOOT resolves to 2 SYMBOLGEN: Macro variable MYBBOOT resolves to 2 SYMBOLGEN: Macro variable MYPRO resolves to MLOGIC(BIGMAC): Parameter MYTOKEN has value 1 MLOGIC(BIGMAC): Parameter MYTITLE2 has value Selected DRI Males & Females Combined MLOGIC(BIGMAC): Parameter MYTITLE3 has value Plant vs Animal-Based Protein Food MLOGIC(BIGMAC): Parameter MYTITLE4 has value 2 Bootstrap Samples MLOGIC(BIGMAC): Parameter MYDOMN has value DHHDDRI MLOGIC(BIGMAC): Parameter MYBOOT has value 2 MLOGIC(BIGMAC): Parameter MYFMT has value format MLOGIC(BIGMAC): Parameter MYDRI has value DHHDDRI MLOGIC(BIGMAC): Parameter MYDRIMAT has value DRIs_Combined_F. MLOGIC(BIGMAC): Parameter MYPROTEINMAT has value SYMBOLGEN: Macro variable MYTOKEN resolves to 1 SYMBOLGEN: Macro variable MYTITLE3 resolves to Plant vs Animal-Based Protein Food ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: &MyToken EQ 1 and &Mytitle3 EQ "All-Sources Protein Foods" 8 The SAS System 10:09 Tuesday, August 23, 2022 ERROR: The macro BIGMAC will stop executing. MLOGIC(BIGMAC): Ending execution. MPRINT(BIGGERMAC): ; MLOGIC(BIGGERMAC): Ending execution. MPRINT(BIGGESTMAC): ; MPRINT(BIGGESTMAC): ods excel close ; NOTE: Writing EXCEL file: /appdata/HPFB_DGPSA/onpp/29-2015 CCHS Nutrition Analysis/Mean amount consumed.xlsx MLOGIC(BIGGESTMAC): %DO loop index variable T is now 2; loop will not iterate again. MLOGIC(BIGGESTMAC): Ending execution. 241 242 243 %LET _CLIENTTASKLABEL=; 244 %LET _CLIENTPROCESSFLOWNAME=; 245 %LET _CLIENTPROJECTPATH=; 246 %LET _CLIENTPROJECTPATHHOST=; 247 %LET _CLIENTPROJECTNAME=; 248 %LET _SASPROGRAMFILE=; 249 %LET _SASPROGRAMFILEHOST=; 250 251 ;*';*";*/;quit;run; 252 ODS _ALL_ CLOSE; 253 254 255 QUIT; RUN; 256
SYMBOLGEN: Macro variable MYTOKEN resolves to 1 SYMBOLGEN: Macro variable MYTITLE3 resolves to All-Sources Protein Foods ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: &MyToken EQ 1 and &Mytitle3 EQ "All-Sources Protein Foods"
&MYTITLE3 has value All-Sources Protein Foods which does not equal "All-Sources Protein Foods". Can you see why?
In addition, the error message probably arises because when the macro processor sees MYTITLE3 whose value starts with All-Sources, it interprets the dash as subtraction, which I'm sure is not what you meant. It wants numbers for subtraction and you have provided text strings for subtraction.
So I think the code you want would be
%if &MyToken EQ 1 and %quote(&Mytitle3) EQ %str(All-Sources Protein Foods) %then ...
which I haven't really tested, but you can test easily.
Side issue: I said "Please show us the ENTIRE log for this DATA step or PROC" which should have probably read "Please show us the ENTIRE log for this DATA step or PROC or macro". We don't need the hundreds of lines before the execution of the macro, PROC or DATA step.
Thank you so much for your help! Much appreciated.
I believe the dash was the problem.
Erik
Strange.
Code:
%macro test(MyToken,Mytitle3);
%if &MyToken EQ 1
and &Mytitle3 EQ "All-Sources Protein Foods"
%then %put 123;
%else %put 456;
%mend;
%test(1,"All-Sources Protein Foods")
%test(2,"All-Sources Protein Foods")
Log:
1 %macro test(MyToken,Mytitle3); 2 %if &MyToken EQ 1 3 and &Mytitle3 EQ "All-Sources Protein Foods" 4 %then %put 123; 5 %else %put 456; 6 %mend; 7 %test(1,"All-Sources Protein Foods") 123 8 %test(2,"All-Sources Protein Foods") 456
Was any of macro variables empty?
Try:
%if %superq(MyToken) EQ 1
and %superq(Mytitle3) EQ "All-Sources Protein Foods"
%then ...
Bart
@yabwon wrote:
Strange.
Code:
%macro test(MyToken,Mytitle3); %if &MyToken EQ 1 and &Mytitle3 EQ "All-Sources Protein Foods" %then %put 123; %else %put 456; %mend; %test(1,"All-Sources Protein Foods") %test(2,"All-Sources Protein Foods")
Log:
1 %macro test(MyToken,Mytitle3); 2 %if &MyToken EQ 1 3 and &Mytitle3 EQ "All-Sources Protein Foods" 4 %then %put 123; 5 %else %put 456; 6 %mend; 7 %test(1,"All-Sources Protein Foods") 123 8 %test(2,"All-Sources Protein Foods") 456
Not strange, you provided the Quotes in the macro parameter. The OP code does not when providing MyTitle3.
If your MYTITLE3 does not contain the actual quotes you compare to then you will get that error.
You might try
%if &MyToken EQ 1 and "&Mytitle3" EQ "All-Sources Protein Foods"
so the quotes exist for the comparison. If you don't then have the quotes in effect you are performing a comparison of
All-Sources Protein Foods EQ "All-Sources Protein Foods"
and all those spaces left of the EQ are in the wrong places for the comparison.
Please note that quotes in Macro code are quite often a cause of interesting problems. It may be better to use the %quote function:
%if &MyToken EQ 1 and %quote(&Mytitle3) EQ %quote(All-Sources Protein Foods)
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.