BookmarkSubscribeRSS Feed
BrahmanandaRao
Lapis Lazuli | Level 10
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

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

Use an appropriate informat like dollar8.2

 

proc sql;
select * ,sum(input(Sales, dollar8.2))as totals from hsum;
quit;
BrahmanandaRao
Lapis Lazuli | Level 10

 vertical sum

PeterClemmensen
Tourmaline | Level 20

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.

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 2209 views
  • 0 likes
  • 3 in conversation