I have a data set that look as follows:
year | month | accrual |
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 |
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 | ||
2017 | 2018 | |
month | n | n |
Jan | . | 10 |
Feb | 2 | 8 |
Mar | 1 | 6 |
Apr | 0 | 9 |
May | 0 | . |
Jun | 0 | . |
Jul | 4 | . |
Aug | 1 | . |
Sep | 4 | . |
Oct | 5 | . |
Nov | 4 | . |
Dec | 4 | . |
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?
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;
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;
Cynthia
Thank you so much.
That was extremely helpful.
Jim
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.