Hi SAS Forum,
I need to categorize the subjects of my large dataset into the cells indicated as xxxx in below table.
This table's column variable is "Bal-band" while raw variable is 'beac_band".
Bal_band | |||
Beac_band | 3000+ | 1001-3000 | <1000 |
1-200 | xxxx | xxxx | |
201-610 | xxxx | ||
611-700 | |||
700+ | |||
0 or none | xxxx |
First, at the highest level subjects have to be filtered like this.
if b_status = 'flcv' and sta_in_12 = '1-30' and use_band ='<100' then do;
To create a flag_variable so that I can identify the subjects to be allocated into
Cells of our intrest in the above table, I have tried the below code.
data want;
set have;
if b_status = 'flcv' and sta_in_12 = '1-30' and use_band ='<100' then do;
if beac_band in ('1-200', ’201-600') and bal_band in ('3000+')
or
if beac_band in ('1-200') and bal_band in('1001-3000')
or
if beac_band in ('0 or none') and bal_band in('3000+')
then Flag = 'Medium';
end;
if …………then do;
……..
…….
End;
un
if …………then do;
……..
…….
End;
RUN;
Question:
An error messege comes like this.
beac_band in ('580-620')
___________
22
18 ! and bal_band in('3000+') then Fog = 'Medium';
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, (, *, **, +, -, /, <, <=, <>, =, >, ><, >=, AND, EQ, GE, GT,
IN, LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, [, ^=, {, |, ||, ~=.
Could you please let me know whether I can or cannot use the above code with several “or” “or” “or”.
Thank you for your help.
Mirisage
Hi:
I believe that you want an ELSE where you show the use of OR. In a SAS IF statement, OR is a logical operator and is meant to be used like this:
IF (name='Alfred' and height = 69) OR name='Alice' then somevar=1;
ELSE IF name='William' OR (name='Jane' and height = 59.8) then somevar=2;
ELSE somevar=3;
For more information about building IF statements, this is a good documentation topic:
SAS(R) 9.3 Statements: Reference
When you need to execute more than 1 statement as a result of a condition being true, then you need to use a DO/END block with your IF statement:
IF (name='Alfred' and height = 69) OR name='Alice' then DO;
somevar=1;
newvar = x * y;
END;
ELSE IF name='William' OR (name='Jane' and height = 59.8) then DO;
somevar=2;
newvar = y*z;
END;
ELSE DO;
somevar=3;
newvar = x*z;
END;
cynthia
Try removing redundant IFs from this statement and add brackets like so:
if (beac_band in ('1-200', ’201-600') and bal_band in ('3000+'))
or
(beac_band in ('1-200') and bal_band in('1001-3000'))
or
(beac_band in ('0 or none') and bal_band in('3000+'))
then Flag = 'Medium';
Hi:
I believe that you want an ELSE where you show the use of OR. In a SAS IF statement, OR is a logical operator and is meant to be used like this:
IF (name='Alfred' and height = 69) OR name='Alice' then somevar=1;
ELSE IF name='William' OR (name='Jane' and height = 59.8) then somevar=2;
ELSE somevar=3;
For more information about building IF statements, this is a good documentation topic:
SAS(R) 9.3 Statements: Reference
When you need to execute more than 1 statement as a result of a condition being true, then you need to use a DO/END block with your IF statement:
IF (name='Alfred' and height = 69) OR name='Alice' then DO;
somevar=1;
newvar = x * y;
END;
ELSE IF name='William' OR (name='Jane' and height = 59.8) then DO;
somevar=2;
newvar = y*z;
END;
ELSE DO;
somevar=3;
newvar = x*z;
END;
cynthia
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.