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

/*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

 

*/

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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'

......

View solution in original post

6 REPLIES 6
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

Astounding
PROC Star

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'

......

RW9
Diamond | Level 26 RW9
Diamond | Level 26

But isn't, when we talk about integer data, 

6 <- 12

Just a complicated way of saying

7 - 12

??

Astounding
PROC Star

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.

bgonth1
Fluorite | Level 6

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.

dunga
Obsidian | Level 7

Hi Astounding, RW3 and bgoth1,

Thanks to each one of you for the help.

Regards

Mirisa

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 1003 views
  • 4 likes
  • 4 in conversation