DATA Step, Macro, Functions and more

How to change Months(character value) into Quarters

Reply
Occasional Contributor
Posts: 14

How to change Months(character value) into Quarters

hi ,

im unable to convert month to quarter 

 

data Customers;
input Cust_id Month Spend;
cards;
1 JAN 100
1 FEB 200
1 MAR 300
1 APR
2 JAN 400
2 FEB 100
2 MAR 600
3 JUN 100
;run;


data CUSTOMER_SEGMENTAION;
input CUST_id Segment;
cards;
1 HIGH
2 MOD
3 LOW
4 HIGH
5 MOD
6 LOW
;run;

 

i want output like

QUARTER

SEGMENT

COUNT_CUST

TOTAL_SPEND

Q1

HIGH

 

 

Q1

MOD

 

 

Q1

LOW

 

 

Q2

HIGH

 

 

Q2

MOD

 

 

Q3

LOW

 

 

……

…………

…………

………..

 

QUARTER WISE (QUARTER LIKE ( (JAN FEB MAR ) for Q1 and same for q2 and q3

SEGEMENT WISE DISTINCT COUNT OF CUSTOMER AND THERE TOTAL SPEND.

if in month it would been a no then it was possible but here month are in character .

So should i use sum case with it???

Super User
Posts: 9,880

Re: How to change Months(character value) into Quarters

Create a value format that converts Jan,Feb,Mar to Q1 (and so on), and use that in a SQL group by, or create a new variable with it, which you can use in by group processing in proc summary etc.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Respected Advisor
Posts: 2,810

Re: How to change Months(character value) into Quarters

[ Edited ]

Use formats to convert your text string months to quarters.

 

Merge the two data sets.

 

Use PROC SUMMARY to produce the sums and count of customers.

 

Also ... hint, hint, hint ... you would be wise to not use text strings such as JAN for months, you make your life simpler if you use numbers for months, 1 is January, 2 is February, and so on, and then converting to quarters is even easier. This advice applies to all calendar data, use either actual numbers, of SAS date values or SAS date/time values, do not use text strings to represent calendar values.

--
Paige Miller
Occasional Contributor
Posts: 14

Re: How to change Months(character value) into Quarters

thanks for the reply ,

was able to solve using if else

easy problem it was

 

Ask a Question
Discussion stats
  • 3 replies
  • 164 views
  • 3 likes
  • 3 in conversation