I have data that I have transposed into numerous columns. The data is structured like this:
name 1-2018 2-2018 3-2018
x 1 2 3
y 4 5 6
z 7 8 9
I want to add a total column to the end of this table, but do not know the best way to do so. The column count changes from month to month as new columns are added.
I'm not sure which PROC is the best way to tackle this.
Being new to SAS, I may not be searching for my topic the best way; if there are similar posts, I apologize.
Make sure you have a naming convention, then you can use the short cut list to reference your variables. So if each of the columns that you need to add start with MONTH_, such as Month_201801, Month_201802, etc then you can do the following:
Total = sum(of month_: );
The other approach is to use a long format and then use PROC TABULATE to create the summaries as needed for reporting.
data have;
input name $ _12018 _22018 _32018;
datalines;
x 1 2 3
y 4 5 6
z 7 8 9
;
data want;
set have;
total=sum(of _numeric_);
run;
Make sure you have a naming convention, then you can use the short cut list to reference your variables. So if each of the columns that you need to add start with MONTH_, such as Month_201801, Month_201802, etc then you can do the following:
Total = sum(of month_: );
The other approach is to use a long format and then use PROC TABULATE to create the summaries as needed for reporting.
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 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.