Help using Base SAS procedures

How to allocate records into grids of a Table?

Accepted Solution Solved
Reply
Super Contributor
Posts: 338
Accepted Solution

How to allocate records into grids of a Table?

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_band3000+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


Accepted Solutions
Solution
‎04-02-2013 10:22 PM
SAS Super FREQ
Posts: 8,676

Re: How to allocate records into grids of a Table?

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

View solution in original post


All Replies
Respected Advisor
Posts: 2,988

Re: How to allocate records into grids of a Table?

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';

Solution
‎04-02-2013 10:22 PM
SAS Super FREQ
Posts: 8,676

Re: How to allocate records into grids of a Table?

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

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 83 views
  • 3 likes
  • 3 in conversation