BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

Hello

I want to use proc report.

I want to have 7 fields in required report.

required fields are:

TEAM
Number of customers in 1806
Sum of Y in 1806
Difference of Sum of Y between 1806 and 1805
PCT difference of Sum of Y between 1806 and 1805
Difference of Sum of Y between 1806 and 1712
PCT difference of Sum of Y between 1806 and 1712

 

My problem is that I am getting also fields that I don't want (because of using across...)

 

 

DATA tbl1;
input ID  mon Team $ Y;
cards;
1  1806  a 10
2  1806  a 11
3  1806  b 12
4  1806  a 13
5  1806  b 14
6  1806  b 15
7  1806  a 16

1  1805  a 10
2  1805  a 11
3  1805  b 12
4  1805  b 13
5  1805  a 14
1  1712  a 8
2  1712  a 9
3  1712  b 10
5  1712  b 11
6  1712  a 12
7  1712  a 13
;
run;


Proc report data=tbl1;
   columns Team mon,(Y=Yn  Y=Ysum ) 
			 ('Comparison to previous month' diff_Y_From_PrevMon    PCT_diff_Y_From_PrevMon)
			('Comparison to last DEC' diff_Y_From_LastDEC   PCT_diff_Y_From_LastDEC)
;
   define Team/ group  order=data  'Team';
   define mon/across order=data  'Month';
   define Yn / n 'Customers'  format=comma12. ;
   define Ysum / sum 'SUM_Y' format=comma12.;

  define diff_Y_From_PrevMon/ computed  'differnce_Y';
			   compute diff_Y_From_PrevMon;
			      diff_Y_From_PrevMon =_c3_-_c5_;
			   endcomp ;
 define PCT_diff_Y_From_PrevMon/ computed  format=percentn9.1  'PCT_differnce_Y';
			   compute PCT_diff_Y_From_PrevMon;
			      PCT_diff_Y_From_PrevMon =(_c3_-_c5_)/_c5_;
			   endcomp ;

  define diff_Y_From_LastDEC/ computed  'differnce_Y';
			   compute diff_Y_From_LastDEC;
			      diff_Y_From_LastDEC =_c3_-_c7_;
			   endcomp ;
 define PCT_diff_Y_From_LastDEC/ computed  format=percentn9.1  'PCT_differnce_Y';
			   compute PCT_diff_Y_From_LastDEC;
			      PCT_diff_Y_From_LastDEC =(_c3_-_c7_)/_c7_;
			   endcomp ;
rbreak after/ summarize;
run;

 

DATA tbl1;
input ID mon Team $ Y;
cards;
1 1806 a
2 1806 a
3 1806 b
4 1806 a
1 1805 a
2 1805 a
3 1805 c
4 1805 b
5 1805 a
1 1712 a
2 1712 a
3 1712 c
5 1712 c
6 1712 a
7 1712 a
;
run;

1 REPLY 1
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Use a procedure or datastep which is designed to do statistics - means, summary etc.  Then report your data out.  I have never seen doing calculations in a reporting procedure to yield a good process.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 710 views
  • 0 likes
  • 2 in conversation