BookmarkSubscribeRSS Feed
mohassan99
Obsidian | Level 7
   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; 

2 REPLIES 2
mkeintz
PROC Star

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.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
ballardw
Super User

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.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 2 replies
  • 1127 views
  • 1 like
  • 3 in conversation