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?
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;
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;
That worked. Simple.
data have;
infile cards dsd;
input num @@;
char=put(num,f12.3 -l);
cards;
6, 6.1, 6.12
;
That worked too. Simple.
@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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.