proc format;
value $PRV_ID 'H0000000' - 'H9999999' = 'Hospital'
'A0000000' - 'A9999999' = 'A...'
'P0000000' - 'P9999999' = 'P...'
'Q0000000' - 'Q9999999' = 'Q...'
'1000000000' - '1999999999' = 'NPI'
'000000001' - '999999999' = 'TIN'
Other='?';
run;
Log:
24 proc format;
25 value $PRV_ID 'H0000000' - 'H9999999' = 'Hospital'
26 'A0000000' - 'A9999999' = 'A...'
27 'P0000000' - 'P9999999' = 'P...'
28 'Q0000000' - 'Q9999999' = 'Q...'
29 '1000000000' - '1999999999' = 'NPI'
30 '000000001' - '999999999' = 'TIN'
31 Other='?';
ERROR: These two ranges overlap: 000000001-999999999 and 1000000000-1999999999 (fuzz=0).
NOTE: The previous statement has been deleted.
32 run;
Because you are formatting a character variable, SAS will use lexicographic ordering (i.e. like in a dictionary, comparing first characters, then second characters, etc). Therefore you can have, where the outer values are 'NPI' and the middle value is 'TIN'.
'000000001' < '1000000000' < '1999999999'
Now if the TIN values another leading zero, you could use:
proc format;
value $PRV_ID 'H0000000' - 'H9999999' = 'Hospital'
'A0000000' - 'A9999999' = 'A...'
'P0000000' - 'P9999999' = 'P...'
'Q0000000' - 'Q9999999' = 'Q...'
'1000000000' - '1999999999' = 'NPI'
'0000000001' - '0999999999' = 'TIN'
Other='?';
run;
would work.
If your actual values for TIN are 9-characters, instead of 10 as I use in the value statement, you could catch and modify those X values, and then successfully use this format.
You may want to double check the logic of the format in general. Ranges of character values often do not behave as expected.
Example:
proc format library=work; value $PRV_ID 'H0000000' - 'H9999999' = 'Hospital' 'A0000000' - 'A9999999' = 'A...' 'P0000000' - 'P9999999' = 'P...' 'Q0000000' - 'Q9999999' = 'Q...' '1000000000' - '1999999999' = 'NPI' /*'000000001' - '999999999' = 'TIN'*/ Other='?'; run; data junk; x='H0A'; put x $prv_id.; run;
Has this result:
39 40 data junk; 41 x='H0A'; 42 put x $prv_id.; 43 run; Hospital
Do you want a value of H0A to have the formatted value of Hospital?
This may be one of those times that you need to generate a data set with the explicit known values and use them to create a CNTLIN dataset.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.