BookmarkSubscribeRSS Feed
Ranjeeta
Pyrite | Level 9
8  data All_dad_nacrs_test;
1189  set dad_nacrs ;
1190
1191  if VAR2 = ('1') and (DAD_Has_Project_340_Information  = '1' ) and
1192  ((substr(DAD_MRDx_Code,1,3) IN: ('I63' 'I64' 'H34')) or
1192! DAD_Administration_of_Acute_Thro  in ('Yes'))
1193  and (DAD_Administration_of_Acute_Thro not in ('Yes, Prior') )
1194  then deno =1 ;
1195  else deno = 0;
1196
1197  if VAR2 = ('1')and (DAD_Has_Project_340_Information  = '1' )
1198  and  ((substr(DAD_MRDx_Code,1,3) IN: ('I63' 'I64' 'H34') or
1198! DAD_Administration_of_Acute_Thro  in ('Yes'))
1199  and  (DAD_Administration_of_Acute_Thro not in ('Yes, Prior') and
1199! (DAD_Administration_of_Acute_Thro  in ('Yes') ))
1200  then NUME =1 ;
      ----         -
      22           79
      202
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, ), *, **, +, -, /,
              <, <=, <>, =, >, ><, >=, AND, EQ, GE, GT, IN, LE, LT, MAX, MIN, NE, NG, NL,
              NOT, NOTIN, OR, ^, ^=, |, ||, ~, ~=.

ERROR 79-322: Expecting a ).

ERROR 202-322: The option or parameter is not recognized and will be ignored.

1201
1202  else nume = 0;
      ----
      160
ERROR 160-185: No matching IF-THEN clause.

1203
1204  run;

NOTE: The SAS System stopped processing this step because of errors.

Hello,

 

Would appreciate advice on correcting the error above 

Also if I am to write multiple if steps instead of 1 big if condition will i still be able to assign a value of deno=1 for all conditions that are satisfied

 

Thanks in advance 

8 REPLIES 8
gamotte
Rhodochrosite | Level 12
Hello,

Line 1198, the first parenthesis isn't closed.
gamotte
Rhodochrosite | Level 12

I just discovered this site that you might find helpful :

http://www.balancebraces.com/

2021-01-11 17_38_01-Results Page_ Balance Braces, Parentheses, Brackets, and Tags in Your Code.png

Ksharp
Super User
Cool. Hope sas could accept this function .
ballardw
Super User

In this bit of code you have ( before Dad_Administration_of_Acute_Thro

that are not needed.


1199  and  (DAD_Administration_of_Acute_Thro not in ('Yes, Prior') and
1199! (DAD_Administration_of_Acute_Thro  in ('Yes') ))
1200  then NUME =1 ;

  Look at the parallel coding you used in lines 1191 - 1195

 

I am not sure I clearly understand this:

Also if I am to write multiple if steps instead of 1 big if condition will i still be able to assign a value of deno=1 for all conditions that are satisfied

However if you need to assign multiple variables based on a long condition then you should look at :

 

If <some very long conditional code> then do;
   var1=value;
   var2=value2;
   var3=value3;
end;
else do;
   var1=othervalue;
   var2=othervalue2;
   var3=othervalue3;
end;

 

Kurt_Bremser
Super User

Avoid unnecessary parentheses, and bring visual structure to your code, so you can see the functional blocks.

if
  VAR2 = '1' and
  DAD_Has_Project_340_Information  = '1' and (
    substr(DAD_MRDx_Code,1,3) in ('I63','I64','H34') or
    DAD_Administration_of_Acute_Thro  = 'Yes'
  ) and
  DAD_Administration_of_Acute_Thro ne 'Yes, Prior' and
  DAD_Administration_of_Acute_Thro = 'Yes'
then NUME = 1;
else NUME = 0;

(note how easy it now is to count the number of opening and closing brackets)

And this can be simplified to

NUME = (
  VAR2 = '1' and
  DAD_Has_Project_340_Information  = '1' and (
    substr(DAD_MRDx_Code,1,3) in ('I63','I64','H34') or
    DAD_Administration_of_Acute_Thro  = 'Yes'
  ) and
  DAD_Administration_of_Acute_Thro ne 'Yes, Prior' and
  DAD_Administration_of_Acute_Thro = 'Yes'
);

since the result of a condition is either 1 (true) or 0 (false).

FreelanceReinh
Jade | Level 19

@Kurt_Bremser wrote:

(...)

And this can be simplified to

NUME = (
  VAR2 = '1' and
  DAD_Has_Project_340_Information  = '1' and (
    substr(DAD_MRDx_Code,1,3) in ('I63','I64','H34') or
    DAD_Administration_of_Acute_Thro  = 'Yes'
  ) and
  DAD_Administration_of_Acute_Thro ne 'Yes, Prior' and
  DAD_Administration_of_Acute_Thro = 'Yes'
);

...


... which could be further simplified to:

NUME = VAR2 = DAD_Has_Project_340_Information = '1' and
       DAD_Administration_of_Acute_Thro = 'Yes';
Astounding
PROC Star

Clearly, any form of simplification will help in understanding this code.  Here's one place.  This code is overly complex:

substr(DAD_MRDx_Code,1,3) IN: ('I63' 'I64' 'H34')

It should become:

DAD_MRDx_Code IN: ('I63' 'I64' 'H34')

That's the whole purpose of using the IN: operator instead of IN.  It automatically makes the comparison based on the smaller number of characters.

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
  • 8 replies
  • 934 views
  • 6 likes
  • 7 in conversation