data have;
input var1 var2 var3;
cards;
1 2 3
4 5 6
7 8 9
;
data want;
set have;
sum=sum(of _numeric_);
run;you mean this?
data want;
set have;
sum=sum(of _numeric_);
run;
data have;
input var1 var2 var3;
cards;
1 2 3
4 5 6
7 8 9
;
data want;
set have;
sum=sum(of _numeric_);
run;you mean this?
data want;
set have;
sum=sum(of _numeric_);
run;
@Ronein wrote:
The issue is that I have a dynamic program that run every month.
Number of fields are increasing every month.
So actually i want to calculate sum along row with non fix number of fields.
That means your data model is wrong. As I believe has been mentioned a time or two.
If you can't use _numeric_ as suggested by @novinosrin - because you have numeric vars that should not be part of the calculation - then all variables need a common prefix, so that you can use
sum = sum(of prefix:)
.
But fixing the data-structure as recommended by @ballardw is the best way to solve the issue.
@andreas_lds wrote:
If you can't use _numeric_ as suggested by @novinosrin - because you have numeric vars that should not be part of the calculation - then all variables need a common prefix, so that you can use
sum = sum(of prefix:).
But fixing the data-structure as recommended by @ballardw is the best way to solve the issue.
or if you have several "prefixes"
sum = sum( of prefix: , of other: , of different: );
or if all of the variables of interest are sequential in column order
sum = sum( firstvar -- lastvar); There are two - in case your browser makes it hard to read.
But for stuff like this providing an example layout of your data and indicating which variables you wanted to sum does not seem unrealistic to ask.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.