DATA Step, Macro, Functions and more

How to summarize numbers (with 2 dots) that are stored in macro variable?

Reply
Occasional Contributor
Posts: 9

How to summarize numbers (with 2 dots) that are stored in macro variable?

Hi!

I have one question.

I have a numers in commax30. format which are saved in macro variable. (e.g.  first numer= 35.258.698, second numer=58.258.369 an so one.., every numer contains 2 dots)

When i try to summarize this two or more numer i get an error bescause numbers has 2 dots.

I tried with more combinations and i do not know how to resolve this problem.

The numbers must be in defined formats commax30. and i do not want define duplicate macro variable just for summarizing.

Does anyone have any idea.

For example:

%let var1=25.598.659;

%let var2=32.589.124;

%let sum=%syseval(&var1+&var2);

%put ∑

Thx for help.

Mladen

Regular Contributor
Posts: 233

How to summarize numbers (with 2 dots) that are stored in macro variable?

Please help me understand why would a number have 2 dots. Can this 25.598.659 be assumed as 25,598,659?

Occasional Contributor
Posts: 9

How to summarize numbers (with 2 dots) that are stored in macro variable?

Hi!

Because my client wants result in this format. 25,598,659 is not acceptable format for my reports.

I can define duplicate macro variable but this is too complicated.

So, i try to fine more elegant solution.

Thx for questions.

PROC Star
Posts: 7,467

How to summarize numbers (with 2 dots) that are stored in macro variable?

Couldn't you just use the commaxw.d format for your reports?  see:

http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000200612.htm

Super User
Posts: 19,770

Re: How to summarize numbers (with 2 dots) that are stored in macro variable?

Is it basically the european format for a number, decimal instead of comma?

I think Hima's question needs to be answered, otherwise how do the numbers add together, ie Do all numbers have 2 periods and do all have 8 digits? 

Assuming you can't just use the commax format in your final report and store intermediaries in the north american standard notation my suggestion would be to convert to comma notation and the reconvert back to commax format. 

%let var1=25.598.659;

%let var2=32.589.124;

%let cvar1=%sysfunc(inputn(&var1, commax30.));

%let cvar2=%sysfunc(inputn(&var2, commax30.));

%put &var1 &var2 &cvar1 &cvar2;

%let sum=%sysfunc(putn(%sysevalf(&cvar1 +&cvar1), commax30.));

Super User
Posts: 11,343

Re: How to summarize numbers (with 2 dots) that are stored in macro variable?

Since you are creating the macro variables as text somewhere DON'T use a format until final output.

Occasional Contributor
Posts: 9

Re: How to summarize numbers (with 2 dots) that are stored in macro variable?

Hi!

Thanks everyone for help and suggestions.


I will try some of this solutions.

Thx, one more time.

Mladen

Frequent Learner
Posts: 1

Re: How to summarize numbers (with 2 dots) that are stored in macro variable?

Hi,

what about when we have commaxw.d, when d>0

for example

%let var1=25.598.659,6;

%let var2=32.589.124,9;

Thanks in advanced.

Ask a Question
Discussion stats
  • 7 replies
  • 232 views
  • 0 likes
  • 6 in conversation