DATA Step, Macro, Functions and more

breaking a data set

Reply
Occasional Contributor
Posts: 8

breaking a data set

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. 

Super Contributor
Posts: 490

Re: breaking a data set

You can use PROC FORMAT

like

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

like


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;
Occasional Contributor
Posts: 8

Re: breaking a data set

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. 

Super Contributor
Posts: 490

Re: breaking a data set

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;
Ask a Question
Discussion stats
  • 3 replies
  • 210 views
  • 0 likes
  • 2 in conversation