BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Tom
Super User Tom
Super User

You need to understand how SAS (or really any computer program) orders text strings.  It is called lexicographical ordering and it works like looking up a word in the dictionary.

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

else if ('333.0' <= code <= '334.9') then code_Descrip="FEVER";

else code_Descrip="OTHER";


Might work for your data, depends on how messy the CODE variable is.

robertrao
Quartz | Level 8

Hi Tom,

would this code select 180.0 and 180.00???

Secondly, why do we use ~ in the below code????????/

proc format;

value $ icdfmt

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

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

other = 'Other';

run;

Reeza
Super User

1. Try it and check it Smiley Happy

2. I include the TILDA because its after 9 so its my quick short cut to say include anything that might have .9X. There are probably other characters that would accomplish the same thing.

robertrao
Quartz | Level 8

Hi Reeza,

can we do like this

put the tilda on the first and fix the last value( I dint want 125.97 ,125.98 and so on...)like shown

'120~'-'125.96'='FEVER';

Thanks

Tom
Super User Tom
Super User

Look at a table of ASCII code to see the relative ordering of the characters.  http://www.ascii-code.com/

Of the characters you are likely to see in an ICD9 code the order would be  ' ' (space), '.' (period), then the digits from 0 to 9. If you have any letters in your strings they would come later with the uppercase letters from A to Z come first, then the lowercase letters from a to z.  The tilde (~) is the largest of printable basic 7 bit ascii codes.

So if you use '120~' as the lower bound then '120' (or '120    ' as SAS would store it an actual variable since all SAS character variables are fixed length) would be less thatn '120~' since '~' is greater than (comes after in the alphabet) a space (' ').

If you use '120' as the lower bound the values like '120 ', '120.' , '120.0' , '120.8'  and '121' would all be included as they are greater than (or equal to) '120'.

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.

Explore Now →
What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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