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

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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