BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
bikash
Calcite | Level 5

I am trying to Recode  'Cause of Death' (DEATHCAUSE) in two group Cause=1 (Heart Disease) and Cause= 0 (Any other cause). Can anyone point what is wrong with my code?

I got this error with my code:  ERROR 180-322: Statement is not valid or it is used out of proper order.

IF ('I00'<=DEATHCAUSE<='I09') OR                                                                                                      

(DEATHCAUSE EQ 'I11') OR                                                                                                                 

(DEATHCAUSE EQ 'I13') OR                                                                                                                 

('I20'<=DEATHCAUSE<='I51') THEN CAUSE=1;                                                                                             

ELSE CAUSE=0;                                                                                                                                     

RUN;

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

Your code is misplaced. However, while I'm not familiar with ICD codes, if they always start with a letter, and there's no difference between the number of leading zeros, then you might want to use something like:

data have;

  input deathcause $;

  cards;

I01

I02

I10

I13

I14

I49

A002

X001

;

data want (drop=type num);

  set have;

  type=substr(strip(deathcause),1,1);

  num=input(substr(deathcause,anydigit(deathcause)),8.);

  if type eq 'I' and

  (

   (0<=num<=9) OR                                                                                                     

   (num EQ 11) OR                                                                                                                

   (num EQ 13) OR                                                                                                                

   (20<=num<=51)

  ) THEN CAUSE=1;

  ELSE CAUSE=0;                                                                                                                                    

run;

My examples only produce two variables because it initially only had one and added cause.

View solution in original post

7 REPLIES 7
ballardw
Super User

You should post the entire program LOG if practical. Often the cause of this particular error can be traced to an unclosed quote, ( or a missing ; in a line above.

Also the LOG usually shows an underscore character under the first position that the error is detected and that is helpful as well.

You need to be very careful with constructs like

('I00'<=DEATHCAUSE<='I09')

with character variables as 'I000' will usually come up as less than 'I09'.

bikash
Calcite | Level 5

Thanks Ballardw,

Statement looks OK. I ran code sent by Arthur on it and it worked.

libname bwmc '\\xxxx\xxxxx\Death Data\SAS Datasets';

data newD13;

set bwmc.D13Copy;

run;

IF ('I00'<=DEATHCAUSE<='I09') OR                                                                                                    

(DEATHCAUSE EQ 'I11') OR                                                                                                               

(DEATHCAUSE EQ 'I13') OR                                                                                                               

('I20'<=DEATHCAUSE<='I51') THEN CAUSE=1;                                                                                           

ELSE CAUSE=0;                                                                                                                                   

RUN;

ballardw
Super User

bikash wrote:

Thanks Ballardw,

Statement looks OK. I ran code sent by Arthur on it and it worked.

libname bwmc '\\xxxx\xxxxx\Death Data\SAS Datasets';

data newD13;

set bwmc.D13Copy;

run;

Having this statement after RUN will cause the out or order error as RUN ends the data step and IF does not start another executable such as DATA, PROC, %macro or options.

IF ('I00'<=DEATHCAUSE<='I09') OR                                                                                                   

(DEATHCAUSE EQ 'I11') OR                                                                                                              

(DEATHCAUSE EQ 'I13') OR                                                                                                              

('I20'<=DEATHCAUSE<='I51') THEN CAUSE=1;                                                                                          

ELSE CAUSE=0;                                                                                                                                  

RUN;

art297
Opal | Level 21

If your statements are within a datasetp they should work.  e.g.:

data have;

  input deathcause $;

  IF ('I00'<=DEATHCAUSE<='I09') OR                                                                                                     

   (DEATHCAUSE EQ 'I11') OR                                                                                                                

   (DEATHCAUSE EQ 'I13') OR                                                                                                                

   ('I20'<=DEATHCAUSE<='I51') THEN CAUSE=1;                                                                                            

  ELSE CAUSE=0;                                                                                                                                    

  cards;

I02

I10

I13

I14

I49

;

bikash
Calcite | Level 5

Thanks Arthur,

I ran your code and got a new table with only two variables ; selected deathcause only (cards) and cause.

Deathcause Cause

I01                    1

i02                    1

i03                    1

I am trying to add variable in existing table which I want to look like this:

Deathcause Cause

I01                  1

I02                  1

A002                0

X001                0

Deathcause is ICD 10 mortality code which is alphanumeric with 3 or 4 character e.g. A01, A001 etc.

art297
Opal | Level 21

Your code is misplaced. However, while I'm not familiar with ICD codes, if they always start with a letter, and there's no difference between the number of leading zeros, then you might want to use something like:

data have;

  input deathcause $;

  cards;

I01

I02

I10

I13

I14

I49

A002

X001

;

data want (drop=type num);

  set have;

  type=substr(strip(deathcause),1,1);

  num=input(substr(deathcause,anydigit(deathcause)),8.);

  if type eq 'I' and

  (

   (0<=num<=9) OR                                                                                                     

   (num EQ 11) OR                                                                                                                

   (num EQ 13) OR                                                                                                                

   (20<=num<=51)

  ) THEN CAUSE=1;

  ELSE CAUSE=0;                                                                                                                                    

run;

My examples only produce two variables because it initially only had one and added cause.

bikash
Calcite | Level 5

Thanks Arthur and Ballardw,

My colleague came up with this code using substr and it worked:

data newd13;

set bwmc.d13copy;

if substr(deathcause,1,2) in ('I0' 'I2' 'I3' 'I4' 'I5') then cause = 1;

else

if substr(deathcause,1,3) in ('I11' 'I13') then cause = 1;

else

  cause = 0;

run;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

New Learning Events in April

 

Join us for two new fee-based courses: Administrative Healthcare Data and SAS via Live Web Monday-Thursday, April 24-27 from 1:00 to 4:30 PM ET each day. And Administrative Healthcare Data and SAS: Hands-On Programming Workshop via Live Web on Friday, April 28 from 9:00 AM to 5:00 PM ET.

LEARN MORE

Discussion stats
  • 7 replies
  • 4307 views
  • 0 likes
  • 3 in conversation