Convert a numeric value to comma

Accepted Solution Solved
Reply
Contributor
Posts: 42
Accepted Solution

Convert a numeric value to comma

Hi Team,

 

How I can convert a numeric value using put and input to comma.

 

var=100000;

 

new_var=100,000;

 

Thanks and regards,

 

JC


Accepted Solutions
Solution
‎02-24-2017 12:38 PM
Super User
Posts: 7,758

Re: Convert a numeric value to comma

Is that a comma for the 1000/1 million etc separation? Then use the comma format:

new_var = put(var,comma8.);

If more digits are needed, increase the width value accordingly.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Super User
Posts: 19,768

Re: Convert a numeric value to comma

PUT will create a character variable. I suspect you want a numeric format

 

format variable comma.;

Contributor
Posts: 42

Re: Convert a numeric value to comma

[ Edited ]

No , Actually I want to convert it to char value because I am concatenating with another variable..

I tried and variable needs to be in char format to concatenate with another variable.

So I need to convert it from:

 

var=100000  to new_var=100,000  -->> new_var in char format

Super User
Posts: 19,768

Re: Convert a numeric value to comma

When concatenating I recommend using CATT/CATX etc family of functions. They don't require a character variable. 

Contributor
Posts: 42

Re: Convert a numeric value to comma

r1=put(input("Range Start"n,15.),comma12.);
r2=put("Range End"n,comma15.);
Range=CATX('_',r1,r2);

Yes I used that function and It worked, thanks for the comment

Solution
‎02-24-2017 12:38 PM
Super User
Posts: 7,758

Re: Convert a numeric value to comma

Is that a comma for the 1000/1 million etc separation? Then use the comma format:

new_var = put(var,comma8.);

If more digits are needed, increase the width value accordingly.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 42

Re: Convert a numeric value to comma

Posted in reply to KurtBremser

Thanks Kurt,

It worked Smiley Happy

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 490 views
  • 0 likes
  • 3 in conversation