BookmarkSubscribeRSS Feed
Himanshu4
Calcite | Level 5

Himanshu4_0-1677881215552.png

need to write a program so that i can get my output as above, can anyone please help?

3 REPLIES 3
PaigeMiller
Diamond | Level 26

First, you need to provide example data, as working SAS data step code (instructions) and not in any other format. I think either PROC REPORT or PROC TABULATE can do this, but that's as far as I can go without having example data.

--
Paige Miller
Himanshu4
Calcite | Level 5
data test;
input client $ sales card $ trn_dt date9.;
format trn_dt date9.;
cards;
WLM 100 Mast '1Jan2023'd
WLM 200 Visa '6Feb2023'd
WLM 400 Disc '7Mar2023'd
WLM 500 Mast '4Apr2023'd
WLM 900 Visa '3May2023'd
WLM 100 Disc '2Jun2023'd
WLM 300 Mast '1Jul2023'd
WLM 100 Visa '8Aug2023'd
WLM 400 Disc '9Sep2023'd
WLM 200 Mast '2Oct2023'd
WLM 200 Visa '3Nov2023'd
WLM 400 Disc '7Dec2023'd
;
run;
PaigeMiller
Diamond | Level 26
data test;
input client $ sales card $ trn_dt date9.;
cards;
WLM 100 Mast 1Jan2023
WLM 200 Visa 6Feb2023
WLM 400 Disc 7Mar2023
WLM 500 Mast 4Apr2023
WLM 900 Visa 3May2023
WLM 100 Disc 2Jun2023
WLM 300 Mast 1Jul2023
WLM 100 Visa 8Aug2023
WLM 400 Disc 9Sep2023
WLM 200 Mast 2Oct2023
WLM 200 Visa 3Nov2023
WLM 400 Disc 7Dec2023
;
run; 

proc summary data=test nway;
    class client card trn_dt card;
    format trn_dt yyq5.;
    var sales;
    output out=stats(drop=_:) sum=;
run;
data stats1;
    lenght name $ 22;
	set stats;
	by client card trn_dt;
	prev_sales=lag(sales);
	if first.card then prev_sales=.;
	q_over_q=sales/prev_sales;
	value=sales; name='Current Quarter Sales'; output;
	value=prev_sales; name='Last Quarter Sales'; output;
	value=q_over_q; name='Q over Q'; output;
run;
proc sort data=stats1;
	by client trn_dt;
run;
proc report data=stats1;
	by client trn_dt;
	columns name (" " value),card;
	define name/" " group order=data;
	define card/across "Card";
	define value/sum " ";
	label client='Client' trn_dt='Quarter';
run;

 

Since you didn't give data that would allow me to obtain 12 month running average, I can't put it into the code.

--
Paige Miller

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 503 views
  • 2 likes
  • 2 in conversation