BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
kbone1975
Fluorite | Level 6

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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.

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20
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;
Reeza
Super User

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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 2878 views
  • 3 likes
  • 3 in conversation