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.
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;
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.
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;
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.
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.