BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
SASuserlot
Barite | Level 11

I have the following number in character format. How Can I change that into the numeric form, including spaces? Is that possible?

'012932 01 001'

1 ACCEPTED SOLUTION

Accepted Solutions
JOL
SAS Employee JOL
SAS Employee

In SAS numeric values can only contain digits 0-9, decimals and E for scientific notation.  But you can create a custom format to display the value in the pattern you want, but you must convert the original character to a number. See steps below:

 

JOL_0-1686930915406.png

 

JOL_1-1686930974619.png

 

View solution in original post

6 REPLIES 6
Reeza
Super User
Numbers don't have spaces. You could rig a formula to have it displayed this way but be a number underneath. Why do you want it to be numeric?
SASuserlot
Barite | Level 11

Sorry for the confusion. I mean to say the format of the number like how @JOL  and @ballardw explained in the solution.

Thank you for asking more questions so that I learn  to be precise.

JOL
SAS Employee JOL
SAS Employee

In SAS numeric values can only contain digits 0-9, decimals and E for scientific notation.  But you can create a custom format to display the value in the pattern you want, but you must convert the original character to a number. See steps below:

 

JOL_0-1686930915406.png

 

JOL_1-1686930974619.png

 

SASuserlot
Barite | Level 11

Thank you, @JOL @ballardw. This is what I am looking for. Thanks to @Tom @Reeza  for your questions and explanations as well.

Tom
Super User Tom
Super User

@SASuserlot wrote:

I have the following number in character format. How Can I change that into the numeric form, including spaces? Is that possible?

'012932 01 001'


And what number would that be?

Looks like THREE numbers to me.  Or really TWO different numbers. 1 is written two different ways because of  different number of leading zeros.  A the first number (12,932) is also written with a leading zero.

ballardw
Super User

@SASuserlot wrote:

I have the following number in character format. How Can I change that into the numeric form, including spaces? Is that possible?

'012932 01 001'


And just what numeric value would that have? Since spaces are not normally part of a number we need to know exactly what numeric value you expect that to have.

What calculations are you going to sue with this numeric value? If the answer is "none" then don't bother, you are just adding complexity.

You can create a custom format to display numeric values in that format but without details it may be insufficient. Example:

proc format;
picture sss
low-high ='00000 00 009'
;
run;

data _null_;
  input x;
  put x= sss. ;
datalines;
1
12
123
1234
12345
123456
1234567
12345678
123456789
1234567890
;

OR

proc format;
picture sss
low-high ='99999 99 999'
;
run;

data _null_;
  input x;
  put x= sss. ;
datalines;
1
12
123
1234
12345
123456
1234567
12345678
123456789
1234567890
;

 

The log shows some formatted values  but would likely need some details as to actual appearance

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 6 replies
  • 788 views
  • 4 likes
  • 5 in conversation