Hello
I run this code and get an error
what is the problem ? How can i solve it?
%MACRO Sort_if_Data_Set_pdgr_Exist;
%if %sysfunc(exist(Add.PCS_&mon._Y_pdgr) %then %do;
proc sort data=Add.PCS_&mon._Y_pdgr(KEEP=lakoach groupk groupk_befov vct_nm_sibat_or) out=Y_pdgr;
by lakoach;
Run;
%end;
%else %do;
data Y_pdgr;
format
lakoach 8.
groupk 8.
groupk_befov 8.
vct_nm_sibat_or $5.
;
stop;
run;
%end;
%MEND Sort_if_Data_Set_pdgr_Exist;
%Sort_if_Data_Set_pdgr_Exist;
LOG
1 The SAS System 08:57 Wednesday, June 4, 2025
ERROR: Macro keyword LET appears as text.
ERROR: Macro keyword LET appears as text.
1 ;*';*";*/;quit;run;
2 OPTIONS PAGENO=MIN;
ERROR: Macro keyword LET appears as text.
3 %LET _CLIENTTASKLABEL='Program';
ERROR: Macro keyword LET appears as text.
4 %LET _CLIENTPROCESSFLOWNAME='Standalone Not In Project';
ERROR: Macro keyword LET appears as text.
5 %LET _CLIENTPROJECTPATH='';
ERROR: Macro keyword LET appears as text.
6 %LET _CLIENTPROJECTPATHHOST='';
ERROR: Macro keyword LET appears as text.
7 %LET _CLIENTPROJECTNAME='';
8 %LET _SASPROGRAMFILE='';
9 %LET _SASPROGRAMFILEHOST='';
ERROR: Macro keyword MACRO appears as text.
10
11 ODS _ALL_ CLOSE;
ERROR: Macro keyword IF appears as text.
12 OPTIONS DEV=SVG;
13 GOPTIONS XPIXELS=0 YPIXELS=0;
ERROR: Macro keyword MEND appears as text.
14 %macro HTML5AccessibleGraphSupported;
15 %if %_SAS_VERCOMP_FV(9,4,4, 0,0,0) >= 0 %then ACCESSIBLE_GRAPH;
16 %mend;
17 FILENAME EGHTML TEMP;
18 ODS HTML5(ID=EGHTML) FILE=EGHTML
19 OPTIONS(BITMAP_MODE='INLINE')
20 %HTML5AccessibleGraphSupported
21 ENCODING='utf-8'
22 STYLE=HTMLBlue
23 NOGTITLE
24 NOGFOOTNOTE
ERROR: Macro keyword MACRO appears as text.
25 GPATH=&sasworklocation
26 ;
ERROR: Macro keyword IF appears as text.
27
28
29 %MACRO Sort_if_Data_Set_pdgr_Exist;
30 %if %sysfunc(exist(Add.PCS_&mon._Y_pdgr) %then %do;
ERROR: Macro keyword END appears as text.
31 proc sort data=Add.PCS_&mon._Y_pdgr(KEEP=lakoach groupk groupk_befov vct_nm_sibat_or) out=Y_pdgr;
ERROR: There is no matching %IF statement for the %ELSE.
ERROR: Macro keyword DO appears as text.
32 by lakoach;
33 Run;
34 %end;
35 %else %do;
36 data Y_pdgr;
37 format
38 lakoach 8.
39 groupk 8.
40 groupk_befov 8.
ERROR: Macro keyword END appears as text.
41 vct_nm_sibat_or $5.
42 ;
2 The SAS System 08:57 Wednesday, June 4, 2025
ERROR: Macro keyword MEND appears as text.
43 stop;
44 run;
45 %end;
ERROR: Macro keyword LET appears as text.
46 %MEND Sort_if_Data_Set_pdgr_Exist;
ERROR: Macro keyword LET appears as text.
47 %Sort_if_Data_Set_pdgr_Exist;
48
ERROR: Macro keyword LET appears as text.
49 %LET _CLIENTTASKLABEL=;
ERROR: Macro keyword LET appears as text.
50 %LET _CLIENTPROCESSFLOWNAME=;
ERROR: Macro keyword LET appears as text.
51 %LET _CLIENTPROJECTPATH=;
ERROR: Macro keyword LET appears as text.
52 %LET _CLIENTPROJECTPATHHOST=;
ERROR: Macro keyword LET appears as text.
53 %LET _CLIENTPROJECTNAME=;
54 %LET _SASPROGRAMFILE=;
55 %LET _SASPROGRAMFILEHOST=;
56
57 ;*';*";*/;quit;run;
58 ODS _ALL_ CLOSE;
59
60
61 QUIT; RUN;
62
You are missing a closing parenthesis of %sysfunc
%sysfunc(exist(Add.PCS_&mon._Y_pdgr)
Good catch, @RichardAD ! This is the "unbalanced" I should have found.
You do not need a macro definition, BTW. A simple %IF %THEN %DO %END has been possible in "open code" for quite some time now.
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.