BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
haider_imam
Calcite | Level 5

hello I have a variable which is in character format for e.g.  var PPP

 

PPP

400

401

402

403

404

405

406

407

408

409

410

 

I want to take everything from 400 to 405 and make it 405 and for 406 to 410 make it 410. This is what I tried 

 

proc format; 

value pppfmt

400 -< 405 = 405

406 -< 410 = 410;

run; 

 

data table1; 

set table; 

format ppp pppfmt.;

run; 

 

but I get an error in the data step saying the format could not be uploaded, I think it has to do with the fact I am using the technique used for formatting numbers on characters. 

 

Thanks in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

You need a character format to format character variables.

 

proc format; 
   value $pppfmt
      '400'-'405'='405'
      '406'-'410'='410'
   ;
   quit; 

View solution in original post

5 REPLIES 5
Reeza
Super User

If they're numbers you could just round it?

 

PPP_CAT = round(input(PPP, 8.) +2.5, 5);

Adding 2.5 ensures it will always round correctly to the value of interest. Make sure to test the boundaries though, ie 400, 405. 

 


@haider_imam wrote:

hello I have a variable which is in character format for e.g.  var PPP

 

PPP

400

401

402

403

404

405

406

407

408

409

410

 

I want to take everything from 400 to 405 and make it 405 and for 406 to 410 make it 410. This is what I tried 

 

proc format; 

value pppfmt

400 -< 405 = 405

406 -< 410 = 410;

run; 

 

data table1; 

set table; 

format ppp pppfmt.;

run; 

 

but I get an error in the data step saying the format could not be uploaded, I think it has to do with the fact I am using the technique used for formatting numbers on characters. 

 

Thanks in advance!


 

haider_imam
Calcite | Level 5
The format is CHAR,
and there are too many values under the variable. I need to narrow it down. Hence trying to figure out how to use PROC Format on CHAR variables.
data_null__
Jade | Level 19

You need a character format to format character variables.

 

proc format; 
   value $pppfmt
      '400'-'405'='405'
      '406'-'410'='410'
   ;
   quit; 
Reeza
Super User
Yeah, but you can convert it to numeric and convert it back to character, I forgot that part. As long as the rule is as originally indicated it would work fine.
Try this:

PPP_CAT = put(round(input(PPP, 8.) +2.5, 5), 8. -l);

Otherwise data null has provided a character format. Be careful with order though for character, because the order is character based. So 1, 10, 100 is less than 2, 20, 200 in character forms.
Reeza
Super User
Any chance these are ICD codes?

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 1355 views
  • 3 likes
  • 3 in conversation