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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.