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

while executing below code of IN operator , the Block resolves to ERROR instead of Hello , when i pass input parameter as FI

 

%macro test(a) /minoperator;

%if %upcase(&a) in (FI BI CA) %then %put Hello;
%else %put ERROR;
%mend test;

%test(FI)

 

here is the Log : 

 

1 The SAS System Friday, September 17, 2021 08:57:00 AM

1 ;*';*";*/;quit;run;
2 OPTIONS PAGENO=MIN;
3 %LET _CLIENTTASKLABEL='Program 6';
4 %LET _CLIENTPROCESSFLOWNAME='Process Flow';
5 %LET _CLIENTPROJECTPATH='C:\Users\B723166\Desktop\Test23.egp';
6 %LET _CLIENTPROJECTPATHHOST='OPJTYTRU99146';
7 %LET _CLIENTPROJECTNAME='Test23.egp';
8 %LET _SASPROGRAMFILE='';
9 %LET _SASPROGRAMFILEHOST='';
10
11 ODS _ALL_ CLOSE;
12 OPTIONS DEV=SVG;
13 GOPTIONS XPIXELS=0 YPIXELS=0;
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
25 GPATH=&sasworklocation
26 ;
NOTE: Writing HTML5(EGHTML) Body file: EGHTML
27
28 %macro test(a) /minoperator;
29
30 %if %upcase(&a) in (FI BI CA) %then %put Hello;
31 %else %put ERROR;
32 %mend test;
33
34 %test(FI)
ERROR
35
36 %LET _CLIENTTASKLABEL=;
37 %LET _CLIENTPROCESSFLOWNAME=;
38 %LET _CLIENTPROJECTPATH=;
39 %LET _CLIENTPROJECTPATHHOST=;
40 %LET _CLIENTPROJECTNAME=;
41 %LET _SASPROGRAMFILE=;
42 %LET _SASPROGRAMFILEHOST=;
43
44 ;*';*";*/;quit;run;
45 ODS _ALL_ CLOSE;
46
47
48 QUIT; RUN;
49

1 ACCEPTED SOLUTION

Accepted Solutions
Aku
Obsidian | Level 7 Aku
Obsidian | Level 7

You are missing quoting from   %if %upcase(&a) in (FI BI CA) %then %put Hello;

Try : %if %upcase(&a) in ('FI','BI','CA') %then %put Hello;

 

View solution in original post

6 REPLIES 6
Aku
Obsidian | Level 7 Aku
Obsidian | Level 7

You are missing quoting from   %if %upcase(&a) in (FI BI CA) %then %put Hello;

Try : %if %upcase(&a) in ('FI','BI','CA') %then %put Hello;

 

Quentin
Super User

This accepted solution looks wrong to me.  You shouldn't need quote marks in the macro language, as shown in the log I posted showing that the original code posted in the question works correctly.

BASUG is hosting free webinars Next up: Mike Raithel presenting on validating data files on Wednesday July 17. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
PaigeMiller
Diamond | Level 26

I agree, @Quentin . The solution marked correct, in fact is not correct. 

 

@learn_SAS_23 Please un-mark that solution as correct.

--
Paige Miller
PeterClemmensen
Tourmaline | Level 20

Remember to use the Options Minoperator.

Quentin
Super User

Your code runs fine for me:

 

1    %macro test(a) /minoperator;
2
3    %if %upcase(&a) in (FI BI CA) %then %put Hello;
4    %else %put ERROR;
5    %mend test;
6
7    %test(FI)
Hello
BASUG is hosting free webinars Next up: Mike Raithel presenting on validating data files on Wednesday July 17. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
learn_SAS_23
Quartz | Level 8

Thanks for all valuable inputs it works now.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 6 replies
  • 903 views
  • 3 likes
  • 5 in conversation