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
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.