i have 3 obs like below i want sum of all 3 in 4th obs
1) 2 (40.0)
2) 1 (20.0)
3) 2 (40.0)
4) 8(100)
@Vijay77 wrote:
i have 3 obs like below i want sum of all 3 in 4th obs
1) 2 (40.0)
2) 1 (20.0)
3) 2 (40.0)
4) 8(100)
How do you get an 8 in the fourth observation?
apologies its 7
@Vijay77 wrote:
apologies its 7
I don't understand how you obtain the number 7. Please explain.
5
hello,
It helps to provide have and want datasets in the form of data steps so we know exactly the type
of data you are dealing with.
If your observations are strings in the form you give in your example, you have
first to extract numbers, for instance with scan and input functions, then you can perform the
summations :
data have;
input x $10.;
cards;
2 (40.0)
1 (20.0)
2 (40.0)
;
run;
data want;
set have end=fend;
drop sum1 sum2;
sum1+input(scan(x,1), best.);
sum2+input(scan(x,2, '()'), best.);
output;
if fend then do;
x=cat(sum1,' (',put(sum2,5.1),')');
output;
end;
run;
In a data set?
data want;
set have end = eof;
retain total;
total + varName;
output;
if eof then do;
varName = total;
output;
end;
drop total;
run;
In a report?
proc print data=have;
var varName;
sum varName;
run;
@Vijay77 wrote:
i have 3 obs like below i want sum of all 3 in 4th obs
1) 2 (40.0)
2) 1 (20.0)
3) 2 (40.0)
4) 8(100)
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: