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

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