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

Hello! If i have a dataset with numbers having two places after decimal, say, 6, 6.1, 6.12 but I want to save them as characters so that they are save as 6.0, 6.10, and 6.12. How can I do that? Is there a SAS function for that? The same when I have numbers with 3 places after the decimal. For example, if the numbers are 6, 6.1, 6.12, and 6.134, I will like to save them as 6.000, 6.100, 6.120, and 6.134. How can I do that?

1 ACCEPTED SOLUTION

Accepted Solutions
muratatik
Obsidian | Level 7

You can use Z format.

 

DATA HAVE;
INPUT X;
Y=PUT(X,Z4.2);
Z=PUT(X,Z5.3);
DATALINES;
6
6.1
6.12
;
RUN;

View solution in original post

5 REPLIES 5
muratatik
Obsidian | Level 7

You can use Z format.

 

DATA HAVE;
INPUT X;
Y=PUT(X,Z4.2);
Z=PUT(X,Z5.3);
DATALINES;
6
6.1
6.12
;
RUN;
RBJ
Fluorite | Level 6 RBJ
Fluorite | Level 6

That worked. Simple.

novinosrin
Tourmaline | Level 20
data have;
infile cards dsd;
input num @@;
char=put(num,f12.3 -l);
cards;
6, 6.1, 6.12 
;
RBJ
Fluorite | Level 6 RBJ
Fluorite | Level 6

That worked too. Simple.

PaigeMiller
Diamond | Level 26

@RBJ wrote:

Hello! If i have a dataset with numbers having two places after decimal, say, 6, 6.1, 6.12 but I want to save them as characters so that they are save as 6.0, 6.10, and 6.12. How can I do that?

 


The problem here (unless you have mis-typed the problem), is that you don't have two decimal places, the resulting first number you say is 6.0 which has one decimal place. So, is this a typo?

 

If you really want 6.00, 6.10 and 6.12, then the answers have been given. If you really want 6.0, 6.10 and 6.12, you would need to perform some IF statements so that exactly six is formatted as (for example) 5.1, while 6.10 and 6.12 are formatted as 5.2, and given what you have told us, this can't be generalized without more information.

 

In the accepted solution, I don't think the Z is needed in the format at all. The Z format adds nothing to this problem.

--
Paige Miller

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
  • 5 replies
  • 1575 views
  • 1 like
  • 4 in conversation