data xyz;
input var1 var2;
monday 13
monday 12
total .
tuesday 10
tuesday 23
total .
wednesday 34
wednesday 43
total .
run;
how to get the sum of by using var1 and place the results for total rows in var2 in data step?
i.e. no proc procedure/proc sql i shall use to get the answer.
Typically, this is not a good idea to store these sums in a SAS data set in the same column as the raw data. Better would be to have these results in a report of some type, or put the sums in a different column. Do you have a preference?
Putting a sum in the same column as the raw data will make downstream work more difficult. Unless you already have downstream code that requires the data be in this layout.
proc sql;
create table want as select *,sum(var2) as sum_var2
from have
group by var1;
run;
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: