BookmarkSubscribeRSS Feed
renalstats
Fluorite | Level 6

What I am trying to do, is use a wildcard for character variables (in this case, ICD-9 codes) within proc format. 

 

To keep things simple (because a lot of ICD coding has a lot of suffixes and we only care for the primary prefix), I am using coding for uncomplicated hypertension (ICD-9 code 401), which has 2 subcodes (4011, 4019).  I do not want to add a format definition for 4011 and 4019 (this becomes much more arduous when dealing with many other ICD-9 codes). I simply want to create a format by the prefix, and everything after the prefix will be assigned the same format definition. 

 

The prefix code I am interested in, in this case, is 401 (as a character).

 

I have tried using a colon

"401:" = "Hypertension Uncomplicated - ICD-9"

in proc format (in an attempt to include 4011 and 4019), to no avail.

 

Here is my code:

 

 

proc format; 
value $test
"401" = "Hypertension Uncomplicated - ICD-9"
; 
run; 
quit; 

data test_form; 
input PatID ICD9$;
datalines; 
1 401
2 4011
3 4019
; 

data test_form; 
set test_form; 
format ICD9 $test.; 
run; 

proc print data = test_form NOOBS;
title "Testing format wildcards"; 
run; 
title; 

 

As for outputs: 

Current Output:
PatIDICD9
1Hypertension Uncomplicated - ICD-9
24011
34019

 

 

Desired Output:
PatIDICD9
1Hypertension Uncomplicated - ICD-9
2Hypertension Uncomplicated - ICD-9
3Hypertension Uncomplicated - ICD-9

 

 

2 REPLIES 2
Tom
Super User Tom
Super User

You can try ranges.

'401' - '4019' = '....'

So that will match any string that sorts between the two values. Like '4010','4012345678' etc.

Or you could try regular expressions, but I think you will need to switch to using an INFORMAT instead of a FORMAT.  At least that is what it looks like on the documentation page.

http://documentation.sas.com/?docsetId=proc&docsetVersion=9.4&docsetTarget=n1jriq5xib5j45n1pwpwzk311...

 

 

renalstats
Fluorite | Level 6
Using a range ("401" - "4019") did work, but in this particular case I know what the range of suffixes are.

I have not tried the regular expressions yet, will attempt.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 2 replies
  • 2469 views
  • 0 likes
  • 2 in conversation