data hsum;
input ID Trans Sales $;
datalines;
01 1 $135.00
01 1 $75.00
01 1 $140.00
01 2 $140.00
02 1 $220.00
03 1 $135.00
03 1 $125.00
03 2 $80.00
;
run;
proc sql;
select * ,sum(input(Sales,?best12.))as totals from hsum;
quit;
how to sum above char sales varibale
Use an appropriate informat like dollar8.2
proc sql;
select * ,sum(input(Sales, dollar8.2))as totals from hsum;
quit;
vertical sum
This is a 'vertical' som of all the values of Charsales? If you want a different result, then please be specific about your desired result.
With all due respect, do not make numeric variables into character variables. This causes problems, and we see this repeatedly, over and over again, in this forum, people have numbers as character variables, and they don't know how to handle this. If you are in control of the creation of this data set, do not make numbers character variables. If you are not in control (someone sent it to you), create numeric variables to replace the character variables, and then summing is easy.
Simple things like this, following good practices rather than bad practices, will help you hugely in your SAS career.
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!
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.