BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Xiaoyi
Obsidian | Level 7

I want to convert a numeric variable (var1) to character (var2) and add "." in to the string like the following. How could I do it? I know how to convert the numeric to character use PUT,  but I failed to put the "." into the converted string. Thank you for helping in advance!

 

Joy

ID     var1          var2

111  745510    745.510

112  742100   742.100

113  745510   745.510

114  745510   745.510

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
If VAR1 is a character variable try INPUT()

INPUT(var1, 8.3);

If VAR1 is a numeric variable then divide by 1000 and format using 8.3.

new_var = var1/1000;
format new_var 8.3;

View solution in original post

3 REPLIES 3
ballardw
Super User

@Xiaoyi wrote:

I want to convert a numeric variable (var1) to character (var2) and add "." in to the string like the following. How could I do it? I know how to convert the numeric to character use PUT,  but I failed to put the "." into the converted string. Thank you for helping in advance!

 

Joy

ID     var1          var2

111  745510    745.510

112  742100   742.100

113  745510   745.510

114  745510   745.510


It might help to show the code you attempted.

The values you show makes me think that a divide by 1000 should have been involved.

Reeza
Super User
If VAR1 is a character variable try INPUT()

INPUT(var1, 8.3);

If VAR1 is a numeric variable then divide by 1000 and format using 8.3.

new_var = var1/1000;
format new_var 8.3;
PGStats
Opal | Level 21

If you want to represent the number with your local conventions, you can use a National Language format such as NLNUM7.0. For example:

 

 71         options LOCALE=German_Germany;
 72         data _null_;
 73            x=123456;
 74            put x nlnum7.0;
 75         run;
 
 123.456
PG

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
  • 3 replies
  • 4198 views
  • 4 likes
  • 4 in conversation