I am getting the following error when running the code below. Any help in debugging would be great 
1                                                          The SAS System                          10:29 Wednesday, February 9, 2022
1          ;*';*";*/;quit;run;
2          OPTIONS PAGENO=MIN;
3          %LET _CLIENTTASKLABEL='Program';
4          %LET _CLIENTPROCESSFLOWNAME='Cluster - Optimization';
5          %LET _CLIENTPROJECTPATH='C:\Users\up0j1eb\Desktop\SNP Simulations\Cut_point_simulation_20220203_AY003.egp';
6          %LET _CLIENTPROJECTPATHHOST='HPZ155CG0502B2G';
7          %LET _CLIENTPROJECTNAME='Cut_point_simulation_20220203_AY003.egp';
8          %LET _SASPROGRAMFILE='';
9          %LET _SASPROGRAMFILEHOST='';
10         
11         ODS _ALL_ CLOSE;
12         OPTIONS DEV=PNG;
13         GOPTIONS XPIXELS=0 YPIXELS=0;
14         FILENAME EGSR TEMP;
15         ODS tagsets.sasreport13(ID=EGSR) FILE=EGSR
16             STYLE=HtmlBlue
17             STYLESHEET=(URL="file:///C:/Program%20Files%20(x86)/SASHome94/SASEnterpriseGuide/7.1/Styles/HtmlBlue.css")
18             NOGTITLE
19             NOGFOOTNOTE
20             GPATH=&sasworklocation
21             ENCODING=UTF8
22             options(rolap="on")
23         ;
NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR
24         
25         GOPTIONS ACCESSIBLE;
ERROR: All positional parameters must precede keyword parameters.
26         
27         
28         %macro analysis(clustergrp = , finalf_ , finalMean= );
29         
30         data WORK.inclusterdat_random9;
31         	set &ClusterGrp.;
32         run;
33         
34         proc distance
35         	data=WORK.inclusterdat_random9
36         	out=distancedat
37         	method=Euclid;
38         	var interval(METRIC);
39         	id contract_id;
40         run;
41         
42         
43         proc cluster data=distancedat method=ward /*trim=1 k=3*/
44         	outtree=treedat noprint;
45         	id contract_id;
46         run;
47         
48         proc tree data=treedat ncl=5 horizontal out=outclusterdat noprint;
49         	id contract_id;
50         run;
51         
52         proc sql;
53         	CREATE TABLE WORK.JOIN AS
54         		SELECT a.*,
55         			b.METRIC
56         		FROM work.outclusterdat a INNER JOIN WORK.inclusterdat_random9 b
2                                                          The SAS System                          10:29 Wednesday, February 9, 2022
57         			ON a.contract_id = b.contract_id
58         		order by CLUSTER DESC;
59         
60         proc sql;
61         	CREATE TABLE &Finalf_. AS
62         		SELECT DISTINCT cluster,
63         			MIN(METRIC) AS LOWER_BOUND
64         		FROM WORK.JOIN
65         			WHERE cluster BETWEEN 1 AND 5
66         				GROUP BY cluster
67         					ORDER BY LOWER_BOUND ASC;
68         quit;
69         
70         %mend;
71         
72         /*Call macro multiple times:*/
73         
74         %analysis(ClusterGrp = Cluster1, Finalf_ = Final1, finalMean = DIAB001);
           _
           180
WARNING: Apparent invocation of macro ANALYSIS not resolved.
ERROR 180-322: Statement is not valid or it is used out of proper order.
WARNING: Apparent invocation of macro ANALYSIS not resolved.
75         %analysis(ClusterGrp = Cluster2, Finalf_ = Final2, finalMean = DIAB001);
           _
           180
ERROR 180-322: Statement is not valid or it is used out of proper order.
WARNING: Apparent invocation of macro ANALYSIS not resolved.
76         %analysis(ClusterGrp = Cluster3, Finalf_ = Final3, finalMean = DIAB001);
           _
           180
ERROR 180-322: Statement is not valid or it is used out of proper order.
WARNING: Apparent invocation of macro ANALYSIS not resolved.
77         %analysis(ClusterGrp = Cluster4, Finalf_ = Final4, finalMean = DIAB001);
           _
           180
ERROR 180-322: Statement is not valid or it is used out of proper order.
WARNING: Apparent invocation of macro ANALYSIS not resolved.
78         %analysis(ClusterGrp = Cluster5, Finalf_ = Final5, finalMean = DIAB001);
           _
           180
ERROR 180-322: Statement is not valid or it is used out of proper order.
WARNING: Apparent invocation of macro ANALYSIS not resolved.
79         %analysis(ClusterGrp = Cluster6, Finalf_ = Final6, finalMean = DIAB001);
           _
           180
ERROR 180-322: Statement is not valid or it is used out of proper order.
3                                                          The SAS System                          10:29 Wednesday, February 9, 2022
WARNING: Apparent invocation of macro ANALYSIS not resolved.
80         %analysis(ClusterGrp = Cluster7, Finalf_ = Final7, finalMean = DIAB001);
           _
           180
ERROR 180-322: Statement is not valid or it is used out of proper order.
WARNING: Apparent invocation of macro ANALYSIS not resolved.
81         %analysis(ClusterGrp = Cluster8, Finalf_ = Final8, finalMean = DIAB001);
           _
           180
ERROR 180-322: Statement is not valid or it is used out of proper order.
WARNING: Apparent invocation of macro ANALYSIS not resolved.
82         %analysis(ClusterGrp = Cluster9, Finalf_ = Final9, finalMean = DIAB001);
           _
           180
ERROR 180-322: Statement is not valid or it is used out of proper order.
WARNING: Apparent invocation of macro ANALYSIS not resolved.
83         %analysis(ClusterGrp = Cluster10, Finalf_ = Final10, finalMean = DIAB001);
           _
           180
ERROR 180-322: Statement is not valid or it is used out of proper order.
84         
85         
86         
87         GOPTIONS NOACCESSIBLE;
88         %LET _CLIENTTASKLABEL=;
89         %LET _CLIENTPROCESSFLOWNAME=;
90         %LET _CLIENTPROJECTPATH=;
91         %LET _CLIENTPROJECTPATHHOST=;
92         %LET _CLIENTPROJECTNAME=;
93         %LET _SASPROGRAMFILE=;
94         %LET _SASPROGRAMFILEHOST=;
95         
96         ;*';*";*/;quit;run;
97         ODS _ALL_ CLOSE;
98         
99         
100        QUIT; RUN;
101        
					
				
			
			
				
			
			
			
			
			
			
			
		SAS does not know about any macro named %ANALYSIS, as far as SAS is concerned this macro doesn't exist.
Where did you see this %ANALYSIS macro? You have to include the macro in your code somehow before you call it, the easiest way is to copy the macro code from wherever you saw it, and paste it into your code at the top, and then run the whole thing again.
The specific error message relates to
ERROR: All positional parameters must precede keyword parameters. 26 27 28 %macro analysis(clustergrp = , finalf_ , finalMean= );
Positional parameters are those that the definition relies on position in the parameter list to assign values and not defined with an =. As such Finalf_ is positional but comes after the keyword parameter clustergrp. With that error no macro was compiled so it cannot be used.
Change the definition to
%macro analysis(clustergrp = , finalf_= , finalMean= );
and at least the first error message should go away.
The SAS error detector can see into the future, it knew two lines before you typed the %MACRO statement that you were going to make a mistake.
ERROR: All positional parameters must precede keyword parameters. 26 27 28 %macro analysis(clustergrp = , finalf_ , finalMean= ); 29
or perhaps it just does a poor job of placing the error message at the point where the error actually is.
Either add an equal sign after FINALF_ .
Or remove the equal sign after CLUSTERGRP.
So that all of the POSITIONAL parameters are defined before any NAMED parameters.
Note you can still pass the values by name in the call to the macro even if you defined the macro to allow you to pass the values by position.
Code/related question is here:
https://communities.sas.com/t5/SAS-Programming/Iteration-to-change-macro-names/m-p/795268
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.