Help using Base SAS procedures

Proc report change column headers

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

Proc report change column headers

I have a data set that look as follows:

 

yearmonthaccrual
201722
201731
201740
201750
201760
201774
201781
201794
2017105
2017114
2017124
2018110
201828
201836
201849

 

my proc report that reads as:

 

proc report data=accrualwithzeroes;
   columns (month year,accrual);
   define month/'month' group order=internal format=months.;
   define year/'accrual' across;
   define accrual/'n';
run;

 

With the results as follows

 

 

 accrual
 20172018
monthnn
Jan.10
Feb28
Mar16
Apr09
May0.
Jun0.
Jul4.
Aug1.
Sep4.
Oct5.
Nov4.
Dec4.
  

 

Which looks mostly how I want it to, except I do want the 'n' to be there.  But, changing it to two single quotes in the define statement still leaves an empty cell there.

 

Is there a way in the report statement to put the 2017 and 2018 where the "n" is?

Or just do away with that column altogether and move the "month" title up in to the earlier row?


Accepted Solutions
Solution
‎05-04-2018 10:00 AM
SAS Super FREQ
Posts: 9,373

Re: Proc report change column headers

Hi:

  Yes, there are 2 ways to do what you want. Both methods are shown below.

Cynthia

 

data testdata;
  infile datalines;
  input year month accrual;
datalines;
2017	2	2
2017	3	1
2017	4	0
2017	5	0
2017	6	0
2017	7	4
2017	8	1
2017	9	4
2017	10	5
2017	11	4
2017	12	4
2018	1	10
2018	2	8
2018	3	6
2018	4	9
;
run;
  
proc report data=testdata;
   title 'Method 1 -- put numeric variable above ACROSS variable';
   columns (month accrual,year);
   define month/'month' group order=internal ;
   define year/'accrual' across;
   define accrual/' ';
run;
   
proc report data=testdata;
   title 'Method 2 -- move header for month into column statement';
   columns ('Month' month) year,accrual;
   define month/' ' group order=internal ;
   define year/'accrual' across;
   define accrual/' ';
run;

 

View solution in original post


All Replies
Solution
‎05-04-2018 10:00 AM
SAS Super FREQ
Posts: 9,373

Re: Proc report change column headers

Hi:

  Yes, there are 2 ways to do what you want. Both methods are shown below.

Cynthia

 

data testdata;
  infile datalines;
  input year month accrual;
datalines;
2017	2	2
2017	3	1
2017	4	0
2017	5	0
2017	6	0
2017	7	4
2017	8	1
2017	9	4
2017	10	5
2017	11	4
2017	12	4
2018	1	10
2018	2	8
2018	3	6
2018	4	9
;
run;
  
proc report data=testdata;
   title 'Method 1 -- put numeric variable above ACROSS variable';
   columns (month accrual,year);
   define month/'month' group order=internal ;
   define year/'accrual' across;
   define accrual/' ';
run;
   
proc report data=testdata;
   title 'Method 2 -- move header for month into column statement';
   columns ('Month' month) year,accrual;
   define month/' ' group order=internal ;
   define year/'accrual' across;
   define accrual/' ';
run;

 

New Contributor
Posts: 4

Re: Proc report change column headers

Posted in reply to Cynthia_sas

Cynthia

Thank you so much.

That was extremely helpful.

 

Jim

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 160 views
  • 0 likes
  • 2 in conversation