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
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;
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).
@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';
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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.