Help using Base SAS procedures

IF condition

Accepted Solution Solved
Reply
Contributor
Posts: 69
Accepted Solution

IF condition

Hello,

 

I have a data of 4300 lines which now I want to take only part of data for regression.

I have a continouse variables which called FOWNFF, FOWNFNF, DG while nf is 0,1 variable

 

I want that my population will be: FOWNFF>0.2 and FOWNFNF>0.2 and if nf=1 than take the variable while it is DG>0.2

where fownff>0.2 and fownfnf>0.2 if nf=1 and dg>0.2;

 

that is what I wrote and got an error. The log is:

ERROR: Syntax error while parsing WHERE clause.

ERROR 22-322: Syntax error, expecting one of the following: ;, !, !!, &, *, **, +, -, /, <, <=, <>, =, >, >=, AND, EQ, GE, GT,

LE, LT, NE, NOT, OR, ^, ^=, |, ||, ~, ~=.

ERROR 76-322: Syntax error, statement will be ignored.

 

Any help will be acceptable

 

Thanks

 

 


Accepted Solutions
Solution
‎08-03-2016 01:42 AM
Super User
Posts: 6,977

Re: IF condition

The statement must either be a where (which means a where condition that is applied directly on the input data before the data step iteration begins) or an if (subsetting if, is processed at the place it is written in the data step).

Within both, you need to define a condition that yields a boolean value (in SAS, this means a numeric value; 0 is false, any non-zero value - usually 1 - is true).

So, if is not allowed within the where condition. You need to build your condition using and, or and not as logical (boolean) operators.

where
  nf = 0 and fownff > 0.2 and fownfnf > 0.2
  or
  nf = 1 and dg > 0.2
;

Note that logical and takes precedence over logical or in the evaluation, so no parentheses are needed.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Solution
‎08-03-2016 01:42 AM
Super User
Posts: 6,977

Re: IF condition

The statement must either be a where (which means a where condition that is applied directly on the input data before the data step iteration begins) or an if (subsetting if, is processed at the place it is written in the data step).

Within both, you need to define a condition that yields a boolean value (in SAS, this means a numeric value; 0 is false, any non-zero value - usually 1 - is true).

So, if is not allowed within the where condition. You need to build your condition using and, or and not as logical (boolean) operators.

where
  nf = 0 and fownff > 0.2 and fownfnf > 0.2
  or
  nf = 1 and dg > 0.2
;

Note that logical and takes precedence over logical or in the evaluation, so no parentheses are needed.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
☑ This topic is solved.

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

Discussion stats
  • 1 reply
  • 230 views
  • 2 likes
  • 2 in conversation