DATA Step, Macro, Functions and more

If condition error

Accepted Solution Solved
Reply
Contributor
Posts: 33
Accepted Solution

If condition error

i tried up whith this condition.

But the 89 series are come up as null ... Why?

data cre_epi;
set creatin7;
if epi_1 ge 90 then  
	epi_1_stage =1; 
if epi_1 ge 60 and epi_1 le 89 then 
	epi_1_stage =2; 
if epi_1 ge 30 and epi_1 le 59 then 
	epi_1_stage =3; 
if epi_1 ge 15 and epi_1 le 29 then 
	epi_1_stage =4; 
if epi_1 lt 15 then 
	epi_1_stage =5; 
if epi_1 =. then 
	epi_1_stage =.; 
if epi_5 ge 90 then
	epi_5_stage =1;
if epi_5 ge 60 and epi_5 le 89 then 
	epi_5_stage =2; 
if epi_5 ge 30 and epi_5 le 59 then 
	epi_5_stage =3; 
if epi_5 ge 15 and epi_5 le 29 then 
	epi_5_stage =4; 
if epi_5 lt 15 then 
	epi_5_stage =5; 
if epi_5 =. then 
	epi_5_stage =.; 
run;
mnoepi_1epi_5epi_1_stageepi_5_stage
12443875.38789.8752.
12441282.07182.07122
11295689.944...

Accepted Solutions
Solution
3 weeks ago
Super User
Posts: 10,280

Re: If condition error

Posted in reply to Sathish_jammy

Very simple. 89.875 is NOT less or equal to 89.

Use this type of conditions:

if epi_1 ge 60 and epi_1 lt 90 then 
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code

View solution in original post


All Replies
Solution
3 weeks ago
Super User
Posts: 10,280

Re: If condition error

Posted in reply to Sathish_jammy

Very simple. 89.875 is NOT less or equal to 89.

Use this type of conditions:

if epi_1 ge 60 and epi_1 lt 90 then 
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Respected Advisor
Posts: 3,065

Re: If condition error

Posted in reply to Sathish_jammy

The value of 89.875 doesn't satisfy any of your conditions. It is not greater than 90. It is not between 60 and 89. etc.

--
Paige Miller
Super User
Super User
Posts: 9,599

Re: If condition error

Posted in reply to Sathish_jammy

This looks more like a job for formats anyways. 

proc format;
  value creatin
    1-15=5
    15-30=4
    30-60=3
    60-90=2
    90-high=1
    other=.;
run;

data want;
  set have;
  format epi_1 epi_5 creatin.;
run;
  
☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 79 views
  • 4 likes
  • 4 in conversation