/*Hi Forum,
I have the below data set. I wanted to create some income bands. To achieve this, I created a format and applied on the dataset.*/
data have;
input income;
cards;
0
15
392
219
95
.
208
1020
12
41
22
65
372
360
0
0
0
393
190
0
0
0
168
93
890
0
14
43
138
52
125
0
24
45
;
run;
/*Creating a format*/
proc format fmtlib;
value val
. = 'Missing'
low-< 0 = '<0'
0 = '0'
1 - 6 = '1 - 6'
>6 - 12 = '>6 - 12'
>12 - 60 = '>12 - 60'
>60 - 120 = '>60 - 120'
>120 - 240 = '>120 - 240'
>240 - 360 = '>240 - 360'
>360 - 480 = '>360 - 480'
>480 - 600 = '>480 - 600'
>600 - 720 = '>600 - 720'
>720 - 840 = '>720 - 840'
>840 - 960 = '>840 - 960'
>960 - 1080 = '>960 - 1080'
>1080 - 1200 = '>1080 - 1200'
>1200 - high = '>1200'
;
run;
/*Creating income bands by Applying the format */
data want;
set have;
Income_band= put (Income, val.);
run;
/*Q: At the end of the Income_band variable that was created, I am getting this notation, which is ">".
Would you help me to get rind of that notation?
Thanks
Mirisa
Missing
<0
0
1-6 >
>6-12 >
>12-60 >
>60-120 >
>120-240 >
>240-360 >
>360-480 >
>480-600 >
>480-600 >
>600-720 >
>720-840 >
>840-960 >
>960-1080 >
>1080-1200 >
>1200
*/
Uses uses a funny-looking syntax to exclude the left-hand endpoint from a range:
value val
. = 'Missing'
low-< 0 = '<0'
0 = '0'
1 - 6 = '1 - 6'
6 <- 12 = '>6 - 12'
12 <- 60 = '>12 - 60'
60 <- 120 = '>60 - 120'
120 <- 240 = '>120 - 240'
......
As your data seems to be integer shouldn't the bands be:
proc format fmtlib; value val . = 'Missing' low--1 = '<0' 0 = '0' 1 - 6 = '1 - 6' 7 - 12 = '>6 - 12' 13 - 60 = '>12 - 60' ... ; run;
I.e. if its not 1-6 then it starts at 7 not > 6.
Uses uses a funny-looking syntax to exclude the left-hand endpoint from a range:
value val
. = 'Missing'
low-< 0 = '<0'
0 = '0'
1 - 6 = '1 - 6'
6 <- 12 = '>6 - 12'
12 <- 60 = '>12 - 60'
60 <- 120 = '>60 - 120'
120 <- 240 = '>120 - 240'
......
But isn't, when we talk about integer data,
6 <- 12
Just a complicated way of saying
7 - 12
??
Absolutely, if the incoming data always contains integer then it's simpler to get rid of the ">". I couldn't be sure that the data would always contain integers (who knows what the future holds?), so I chose to use a more robust approach.
Below is the modified code:
data have;
input income;
cards;
0
15
392
219
95
.
208
1020
12
41
22
65
372
360
0
0
0
393
190
0
0
0
168
93
890
0
14
43
138
52
125
0
24
45
;
run;
proc format fmtlib;
value val
. = 'Missing'
low-< 0 = '<0'
0 = '0'
1<-6 = '1 - 6'
6<-12 = '>6 - 12'
12<-60 = '>12 - 60'
60<-120 = '>60 - 120'
120<-240 = '>120 - 240'
240<-360 = '>240 - 360'
360<-480 = '>360 - 480'
480<-600 = '>480 - 600'
600<-720 = '>600 - 720'
720<-840 = '>720 - 840'
840<-960 = '>840 - 960'
960<-1080 = '>960 - 1080'
1080<-1200 = '>1080 - 1200'
1200<-high = '>1200'
;
run;
data want;
set have;
format income val.;
run;
proc print data=want;
run;
The code that you used included, ex: <1200-high for the assignment for the format, which is why SAS was printing '>1200>'. Instead you need to put the syntax 1200<-high and apply for the code. After that you used a put statement, which is the wrong code to use for this situation. Use the format statement instead to apply the format val. that you just created. If you wanted to permanently associate the format with the data, then you need to create a new variable (incomechar in the code below) and use the put function like you did initially.
data want;
set have;
incomechar=put(income,val.);
run;
Hope this helps.
Hi Astounding, RW3 and bgoth1,
Thanks to each one of you for the help.
Regards
Mirisa
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.