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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.