Do you want the maximum value in the new column, or the value of a specific observation?
Maximum:
proc sql;
create table want as
select
have.*,
max(profit) as X
from have;
quit;
Specific:
proc sql;
create table want as
select
have.*,
(select profit from have where company = 'paytm') as X
from have;
quit;
You want a new observation with company = 'Total' and profit = sum of profits?
This is mostly needed for reporting, and the SAS procedures for that can handle it, so there's no need to add an observation.
But just to show you how it's done:
data want;
set have end=eof;
retain sum_profit 0;
output;
sum_profit + profit;
if eof
then do;
company = 'Total';
profit = sum_profit;
output;
end;
drop sum_profit;
run;
Do you want the maximum value in the new column, or the value of a specific observation?
Maximum:
proc sql;
create table want as
select
have.*,
max(profit) as X
from have;
quit;
Specific:
proc sql;
create table want as
select
have.*,
(select profit from have where company = 'paytm') as X
from have;
quit;
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!
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.