Dear SAS community,
Would someone be so kind to help me with a small challenge? It is probably very simple, but being a beginner I have not been able to figure it out: I have a dataset with two columns (A and B) that very simplified looks something like this:
A B
Cars 90
Buses 50
Planes 10
Helicopters 2
and I would like to create an additional column C, where the value in each row is the sum of all the values in column B, like this:
A B C
Cars 90 152
Buses 50 152
Planes 10 152
Helicopters 2 152
Thank you very much for your kind help!
Best regards,
Karoline
proc sql;
create table want as
select *, sum(b) as c
from your_dataset;
quit;
proc sql;
create table want as
select *, sum(b) as c
from your_dataset;
quit;
Thank you very much @novinosrin! That worked 🙂 I am grateful for your quick help.
Best regards,
Karoline
And if you may prefer a datastep instead-
data want;
set your_dataset(in=t1) your_dataset(in=t2);
if t1 then c+b;
if t2;
run;
Nearly 200 sessions are now available on demand in the Innovate Hub.
Watch Now →SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.