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

Hi All,

 

Can anyone help me to exhibit the numeric value with 2 decimal points as below

10010 should be represented as 10010.00

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

Below some sample code for both a numerical and a character variable.

If your variable is of type character then we must first convert the string to an number using an input statement and then use a put statement with a numerical format to create a string as you want it in your character variable. The character variable must have a length long enough to hold the additional 3 characters (the dot and two digits).

data have;
  input @1 myvar_num @1 myvar_char $;
  datalines;
20010
20050
20070
20014
;
 
data want;
  set have;
  format myvar_num 16.2;
  myvar_char=put(input(myvar_char,best32.),16.2 -l);
run;

proc print data=want;
run;

Patrick_0-1632301253111.png

 

View solution in original post

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

Apply an appropriate format

 

data _null_;
   n = 10010;
   put n = 8.2;
run;
r3570
Obsidian | Level 7

I am not able to get the required out put.

 

I have the values as below

 

20010

20050

20070

20014

 

i need the below output.

 

20010.00

20050.00

20070.00

20014.00

 

Need a pgrm so that i can apply the same with minor changes.

Kurt_Bremser
Super User

See this for proof:

data want;
input number;
format number 8.2;
datalines;
20010
20050
20070
20014
;

proc print data=want noobs;
run;

Result:

number
20010.00
20050.00
20070.00
20014.00

If you have trouble with your application of this, please post the log.

Patrick
Opal | Level 21

Below some sample code for both a numerical and a character variable.

If your variable is of type character then we must first convert the string to an number using an input statement and then use a put statement with a numerical format to create a string as you want it in your character variable. The character variable must have a length long enough to hold the additional 3 characters (the dot and two digits).

data have;
  input @1 myvar_num @1 myvar_char $;
  datalines;
20010
20050
20070
20014
;
 
data want;
  set have;
  format myvar_num 16.2;
  myvar_char=put(input(myvar_char,best32.),16.2 -l);
run;

proc print data=want;
run;

Patrick_0-1632301253111.png

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1283 views
  • 0 likes
  • 4 in conversation