Hi all,
I created this SAS code, its a bit long but its a very simple code. I dont know what the error is here.
Can someone please figure out what this error means and how to resolve it.
Thanks. This is the log.
MPRINT(DEMO): proc sql ;
NOTE: Line generated by the invoked macro "DEMO".
229 select 38 as a, "Black or African American" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as
229 ! Percent from derived._02a_folfiri_demo where new_race='Black or African American' union all select 39 as a, "White" as
____
22
____
76
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, (, *, **, +, -, '.', /, <, <=, <>, =, >, >=, AND, EQ, EQT,
GE, GET, GROUP, GT, GTT, HAVING, LE, LET, LT, LTT, NE, NET, OR, ORDER, ^=, |, ||, ~=.
ERROR 76-322: Syntax error, statement will be ignore
This is the code;%macro demo;
proc sql;
select N(distinct PatientID) into:denom
from derived._02a_folfiri_demo ;
quit;
proc means data=derived._02a_folfiri_demo mean STD median Q1 Q3 min max;
var age height weight bmi cci_score neutrophil lymphocyte NLR bilrubin;
output out= stat_sum mean()= STD()= median()= Q1()= Q3()= Min()= Max()=/autoname;
run;
proc sql ;
create table _03_demo_folfiri as
select 1 as a, "Total Cohort" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where not PatientID union all
select 2 as a, "Index_Age" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where not PatientID union all
select 3 as a, "18-44" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where age_grp ='18-44' union all
select 4 as a, "45-64" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where age_grp ='45-64' union all
select 5 as a, "65-74" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where age_grp ='65-74' union all
select 6 as a, "75 and older" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where age_grp ='75 and older' union all
select 7 as a, "Age sum" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where not PatientID union all
select 8 as a, "Mean[SD]" as col, age_Mean as pt_num, age_StdDev as Percent from stat_sum union all
select 9 as a, "Median" as col, age_Median as pt_num from stat_sum union all
select 10 as a, "Q1-Q3" as col, age_Q1 as pt_num, age_Q3 as Percent from stat_sum union all
select 11 as a, "Height" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where not PatientID union all
select 12 as a, "Mean[SD]" as col, height_Mean as pt_num, height_StdDev as Percent from stat_sum union all
select 13 as a, "Median" as col, height_Median as pt_num from stat_sum union all
select 14 as a, "Q1-Q3" as col, height_Q1 as pt_num , height_Q3 as Percent from stat_sum union all
select 15 as a, "min-max" as col, height_Min as pt_num , height_Max as Percent from stat_sum union all
select 16 as a, "Weight" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where not PatientID union all
select 17 as a, "Mean[SD]" as col, weight_Mean as pt_num, weight_StdDev as Percent from stat_sum union all
select 18 as a, "Median" as col, weight_Median as pt_num from stat_sum union all
select 19 as a, "Q1-Q3" as col, weight_Q1 as pt_num, weight_Q3 as Percent from stat_sum union all
select 20 as a, "min-max" as col, weight_Min as pt_num , weight_Max as Percent from stat_sum union all
select 21 as a, "BMI" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where not PatientID union all
select 22 as a, "Mean[SD]" as col, bmi_Mean as pt_num, bmi_StdDev as Percent from stat_sum union all
select 23 as a, "Median" as col, bmi_Median as pt_num from stat_sum union all
select 24 as a, "Q1-Q3" as col, bmi_Q1 as pt_num, bmi_Q3 as Percent from stat_sum union all
select 25 as a, "min-max" as col, bmi_Min as pt_num , bmi_Max as Percent from stat_sum union all
select 26 as a, "Sex" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where not PatientID union all
select 27 as a, "Male" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where new_gender='Male' union all
select 28 as a, "Female" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where new_gender='Female' union all
select 29 as a, "Unknown" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where new_gender='Unknown' union all
select 30 as a, "Tumor location" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where not PatientID union all
select 31 as a, "Head" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where PrimarySite='Head' union all
select 32 as a, "Body" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where PrimarySite='Body' union all
select 33 as a, "Tail" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where PrimarySite='Tail' union all
select 34 as a, "Overlapping" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where PrimarySite='Overlapping sites' union all
select 35 as a, "Pancreas NOS" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where PrimarySite='Pancreas, NOS' union all
select 36 as a, "Race" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where not PatientID union all
select 37 as a, "Asian" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where new_race='Asian' union all
select 38 as a, "Black or African American" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where new_race='Black or African American' union all
select 39 as a, "White" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where new_race='White' union all
select 40 as a, "Other Race" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where new_race='Other Race' union all
select 41 as a, "Null" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where new_race='Null' union all
select 42 as a, "Ethnicity" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where not PatientID union all
select 43 as a, "Hispanic or Latino" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where new_ethnicity ='Hispanic or Latino' union all
select 44 as a, "Null" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where new_ethnicity ='Null' union all
select 45 as a, "Geographic location" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where not PatientID union all
select 46 as a, "Northeast" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where new_state='Northeast' union all
select 47 as a, "Midwest" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where new_state='Midwest' union all
select 48 as a, "South" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where new_state='South' union all
select 49 as a, "West" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where new_state='West' union all
select 50 as a, "Unknown" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where new_state='Unknown' union all
select 51 as a, "Smoking Status" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where not PatientID union all
select 52 as a, "History of smoking" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where SmokingStatus='History of smoking' union all
select 53 as a, "Unknown/Not documented" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where SmokingStatus='Unknown/not documented' union all
select 54 as a, "No History of smoking" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where SmokingStatus='No history of smoking' union all
select 55 as a, "Insurance(Multiple)" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_ins where not PatientID union all
select 56 as a, "Medicare" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02b_folfiri_ins where insurance='Medicare' union all
select 57 as a, "Medicaid" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_ins where insurance='Medicaid' union all
select 58 as a, "Commercial health plan" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_ins where insurance='Commercial Health Plan' union all
select 59 as a, "Other Government Health Plan" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_ins where insurance='Other Government Program' union all
select 60 as a, "Self pay" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_ins where insurance='Medicare' union all
select 61 as a, "Patient Assistance Program" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_ins where insurance='Patient Assistance Program' union all
select 62 as a, "Workers Compensation" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_ins where insurance='Workers Compensation' union all
select 63 as a, "Other Payer-Type Unknown" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_ins where insurance='Other Payer - Type Unknown' union all
select 64 as a, "Unknown/Missing" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_ins where insurance='Unknown/Missing' union all
select 65 as a, "ECOG_score" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where not PatientID union all
select 66 as a, "0" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where Ecogvalue=0 union all
select 67 as a, "1" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where Ecogvalue=1 union all
select 68 as a, "2" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where Ecogvalue=2 union all
select 69 as a, "3" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where Ecogvalue=3 union all
select 70 as a, "4" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where Ecogvalue=4 union all
select 71 as a, "Missing" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where Ecogvalue= . union all
select 72 as a, "Charlson Comobidity Index" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where not PatientID union all
select 73 as a, "0/Unknown" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where cci_score=0 union all
select 74 as a, "1" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where cci_score=1 union all
select 75 as a, "2" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where cci_score=2 union all
select 76 as a, "3" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where cci_score=3 union all
select 77 as a, "4+" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where cci_score gt 4 union all
select 78 as a, "CCI index(sum)" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where not PatientID union all
select 79 as a, "Mean[SD]" as col, cci_score_Mean as pt_num, cci_score_StdDev as Percent from stat_sum union all
select 80 as a, "Median" as col, cci_score_Median as pt_num from stat_sum union all
select 81 as a, "qi-q3" as col, cci_score_Q1 as pt_num, cci_score_Q3 as Percent from stat_sum union all
select 82 as a, "min-max" as col, cci_score_Min as pt_num, cci_score_Max as Percent from stat_sum union all
select 83 as a, "Albumin" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where not PatientID union all
select 84 as a, "<40 g/L" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where alb_cat='<40g/L' union all
select 85 as a, ">=40 g/L" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where alb_cat='>=40g/L' union all
select 86 as a, "Unknown" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where alb_cat='Unknown' union all
select 87 as a, "Neutrophil count (sum)" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where not PatientID union all
select 88 as a, "Mean[SD]" as col, neutrophil_Mean as pt_num, neutrophil_StdDev as Percent from stat_sum union all
select 89 as a, "Median" as col, neutrophil_Median from stat_sum union all
select 90 as a, "q1-q3" as col, neutrophil_Q1 as pt_num, neutrophil_Q3 as Percent from stat_sum union all
select 91 as a, "min-max" as col, neutrophil_Min as pt_num, neutrophil_Max as Percent from stat_sum union all
select 92 as a, "Lymphocyte(sum)" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demowhere not PatientID union all
select 93 as a, "Mean[SD]" as col, lymphocyte_Mean as pt_num, lymphocyte_Stddev as Percent from stat_sum union all
select 94 as a, "Median" as col, lymphocyte_Median as pt_num from stat_sum union all
select 95 as a, "q1-q3" as col, lymphocyte_Q1 as pt_num, lymphocyte_Q3 as Percent from stat_sum union all
select 96 as a, "min-max" as col, lymphocyte_Min as pt_num, lymphocyte_mMx as Percent from stat_sum union all
select 97 as a, "NLR(sum)" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where not PatientID union all
select 98 as a, "Mean[SD]" as col, NLR_Mean as pt_num, NLR_Stddev as Percent from stat_sum union all
select 99 as a, "Median" as col, NLR_Median as pt_num from stat_sum union all
select 100 as a, "q1-q3" as col, NLR_q1 as pt_num, NLR_q3 as Percent from stat_sum union all
select 101 as a, "min-max" as col, NLR_min as pt_num, NLR_max as Percent from stat_sum union all
select 102 as a, "Bilrubin" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where not PatientID union all
select 103 as a, "Mean[SD]" as col, bilrubin_Mean as pt_num, bilrubin_Stddev as Percent from stat_sum union all
select 104 as a, "Median" as col, bilrubin_Median as pt_num from stat_sum union all
select 105 as a, "q1-q3" as col, bilrubin_Q1 as pt_num, bilrubin_Q3 as Percent from stat_sum union all
select 106 as a, "min-max" as col, bilrubin_Min as pt_num, bilrubin_Max as Percent from stat_sum union all
select 107 as a, "Practice Type" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where not PatientID union all
select 108 as a, "Academic" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where PracticeType='ACADEMIC' union all
select 109 as a, "Community" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where PracticeType='COMMUNITY' union all
select 110 as a, "Line Number at index" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where not PatientID union all
select 111 as a, "1" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where line_index=1 union all
select 112 as a, "2" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where line_index=2 union all
select 113 as a, "3" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where line_index=3 union all
select 114 as a, "4+" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where line_index gt 4 union all
select 115 as a, "Use of growth factor" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where not PatientID union all
select 116 as a, "No" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where growth_factor='No' union all
select 117 as a, "Yes" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where growth_factor='Yes'
;
quit;
%mend demo;
%demo;
I copy/pasted the code you've posted into Notepad++ Here what I found:
select 38 as a, "Black or African American" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where new_race='Black or African American' union all
select 39 as a, "White" as col, N(distinct PatientID) as pt_num, N(distinct PatientID)/&denom. as Percent from derived._02a_folfiri_demo where new_race='White' union all
It looks like you have an unreadable special character in line 38 "new_race". Try deleting it from your macro code.
But I dont have any special unreadabel character?
@manya92 wrote:
But I dont have any special unreadabel character?
It might just be invisible to you. Try retyping that line of the file.
Otherwise perhaps something else in your process is causing the strange character.
Are you using SAS/Connect to remote submit this macro definition?
Same old, same old:
Get working code before you wrap it in a macro definition.
BTW the macro as such solves NO purpose at all, you don't have macro code or use a mscro parameter. The macro only obfuscates your code and makes your log less readable. Remove it.
@manya92 wrote:
I havent copied my entire code, I have a macro parameter, because i need to run the same code for another dataset. I will have to copy the entire code again for it. Thats why I used MACRO. And also i ran my program befroe i used MACROS
Obviously not, or you would have caught the invalid character earlier and not suspected the macro.
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.