Help using Base SAS procedures

IF CONDITION IN SAS

Accepted Solution Solved
Reply
Super Contributor
Posts: 1,040
Accepted Solution

IF CONDITION IN SAS

I am getting the following error message when I use the code below

Could someone point me in the right direction????

data want;

set have;

if code in('180'-'310.99') then code_Descrip="AIDS";

else if code in('333.0'-'333.9', '334.0'-'334.9') then code_Descrip="FEVER";

else code_Descrip="OTHER";

run;

ERROR 22-322: Syntax error, expecting one of the following: a quoted string,
              a numeric constant, a datetime constant, a missing value, iterator, (, ), ','.

ERROR 200-322: The symbol is not recognized and will be ignored.

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

Thanks


Accepted Solutions
Solution
‎11-20-2013 03:46 PM
Super User
Posts: 17,840

Re: IF CONDITION IN SAS

You need to use formats to define the categories and then apply them generally.

proc format;

value $ icdfmt

  '180'-'310.99~' = 'AIDS'

'333.0'-'333.9~', '334.0'-'334.9~'='Fever'

other = 'Other';

run;

Are you using Standard ICD9/10 or some other classification system? If so the University of Manitoba has SAS code that provides different classifications.

View solution in original post


All Replies
Trusted Advisor
Posts: 1,615

Re: IF CONDITION IN SAS

you want to separate the possible values in the IN condition with a comma, not a hyphen as you did

Super Contributor
Super Contributor
Posts: 440

Re: IF CONDITION IN SAS

can he use if code in('333.0' :'333.9', '334.0':'334.9') or is the ":" only for ranges of num values?

Regular Contributor
Posts: 244

Re: IF CONDITION IN SAS

":" is not only numeric only, but it is *integer* only.

Super Contributor
Super Contributor
Posts: 440

Re: IF CONDITION IN SAS

Thanks Snoopy369

Super User
Posts: 17,840

Re: IF CONDITION IN SAS

Are you looking for ranges of codes rather than the two codes alone?

Super Contributor
Posts: 1,040

Re: IF CONDITION IN SAS

Yes.I am looking for the ranges.

How can i use proc format??Is it possible?

Thnks

Trusted Advisor
Posts: 1,615

Re: IF CONDITION IN SAS

Range:

if code>=180 and code<=310.99 then code_Descrip="AIDS";

Solution
‎11-20-2013 03:46 PM
Super User
Posts: 17,840

Re: IF CONDITION IN SAS

You need to use formats to define the categories and then apply them generally.

proc format;

value $ icdfmt

  '180'-'310.99~' = 'AIDS'

'333.0'-'333.9~', '334.0'-'334.9~'='Fever'

other = 'Other';

run;

Are you using Standard ICD9/10 or some other classification system? If so the University of Manitoba has SAS code that provides different classifications.

Super Contributor
Posts: 1,040

Re: IF CONDITION IN SAS

Hi,

Thanks for the reply,

This is not a standard classification. I was giving it in general.

I have a question in your code..

WHAT IS THE CURLY HYPHEN????WHATS ITS USE???

'180'-'310.99~'

Thanks

Super User
Posts: 17,840

Re: IF CONDITION IN SAS

So 180 and 310.99 are not ICD codes? If not, then please disregard my posts.

Super Contributor
Posts: 1,040

Re: IF CONDITION IN SAS

HERE you Go..

These are ICD9 codes

data want;

set have;

if code in('410.0'-414.09) then code_Descrip="HEART DISEASE";

else if code in('250.0'-'250.6', '250.52'-'250.93) then code_Descrip="DIABETES";

else code_Descrip="OTHER";

run;

If this format works for ICD9 then could you explain to me about the ~

proc format;

value $ icdfmt

  '410.0'-414.09~' = 'HEART DISEASE'

'250.0'-'250.6~', '250.52'-'250.93~'='DIABETES'

other = 'Other';

run;

Super User
Posts: 17,840

Re: IF CONDITION IN SAS

A general programming principle I was taught and follow is if you're recoding something check the boundaries, by checking just above, the boundary and just below and a few random values between. This will catch most recoding mistakes.

See the example below and look at the what happens for Diabetes and 250.59 and 250 rather than 250.0

proc format;

value $ icdfmt

  '410.0'-'414.9~' = 'HEART DISEASE'

'250.0'-'250.6'='DIABETES'

other = 'Other';

invalue $ icdfmt

  '410.0'-'414.9~' = 'HEART DISEASE'

'250.0'-'250.6'='DIABETES'

other = 'Other';

run;

data random;

input code $;

cards;

410.23

410.05

410

410.0

411.1

411.23

413.99

414

414.9

414.99

415.0

415

416

250.0

250

250.99

250.6

250.69

250.99

245.3

;

run;

data check;

    set random;

    icd_code=code;

    format icd_code $icdfmt.;

    icd_code2=input(code, $icdfmt.);

run;

Super Contributor
Posts: 333

Re: IF CONDITION IN SAS

Yeah it looks like they want a range of ICD9 codes?

if you are looking for the full set of codes you could test the substr of the first three characters and test that result.

Ive also used format and put statements for more complex health care codes.

EJ

Regular Contributor
Posts: 244

Re: IF CONDITION IN SAS

if 180 le input(code,BEST12.)  le 310.99 may be the better way to do this.  IN with colon doesn't work with decimals (it expands the integers only). 

☑ This topic is SOLVED.

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

Discussion stats
  • 20 replies
  • 812 views
  • 6 likes
  • 7 in conversation