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

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
proc sql;
 create table want as
 select *, sum(b) as c
 from your_dataset;
quit;

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20
proc sql;
 create table want as
 select *, sum(b) as c
 from your_dataset;
quit;
KarolineN
Obsidian | Level 7

Thank you very much @novinosrin! That worked 🙂 I am grateful for your quick help. 

 

Best regards,

Karoline

novinosrin
Tourmaline | Level 20

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;

SAS Innovate 2025: Call for Content

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!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

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.

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