01-31-2016 05:12 AM
I am having a car sales data file. Wanted to berak the data set where it can give me groups on price ranges.
Having price ranges between 1 to 50 . Want to create 4 groups of data 1-10, 10-20,20-30 and so on.
How to do this via simple code.
01-31-2016 07:23 AM
You can use PROC FORMAT
proc format; value rangefmt 1 -<10 = '01-10' 10 -< 20 = '10-20' 20 -< 30 = '20-30' 30 -< 40 = '30-40' 40 - 50 = '40-50' ; data want; set have; code=put(price, rangefmt.); run;
or you can use noraml IF/ELSE statments
data want; set have; if 1 <= price < 10 then code='01-10'; else if 10 <= price < 20 then code='10-20'; else if 20 <= price < 30 then code='20-30'; else if 30 <= price < 40 then code='30-40'; else if 40 <= price <= 50 then code='40-50'; run;
02-05-2016 01:34 AM
The above solution stands good but what actually I'm looking for is to realign the whole table on basis of price where if price is less than 10 then that entire set should group as one set , then another set on price range of 10-20 and so on. The above solution just creates another column named as code and assign each row a vlaue on identification of price.
02-05-2016 03:57 AM
I am not sure what you want exactly. How your table looks is another issue and can be done by different ways.
For example you can use PROC REPORT
proc report data=have SPANROWS ; column code price; define code / order 'Groups'; define price/ display 'Price'; run;