- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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!
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You need a character format to format character variables.
proc format;
value $pppfmt
'400'-'405'='405'
'406'-'410'='410'
;
quit;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You need a character format to format character variables.
proc format;
value $pppfmt
'400'-'405'='405'
'406'-'410'='410'
;
quit;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content