BookmarkSubscribeRSS Feed
adi121
Fluorite | Level 6

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???

3 REPLIES 3
Kurt_Bremser
Super User

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.

PaigeMiller
Diamond | Level 26

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
adi121
Fluorite | Level 6

thanks for the reply ,

was able to solve using if else

easy problem it was

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 3 replies
  • 1245 views
  • 3 likes
  • 3 in conversation