I had such a wonderful response to add leading zeros to data that I am now asking for help in adding training zeros.
Any suggestions would be appreciated.
Hi,
It would help to provide examples of what you have and what you'd like it to change to.
Is this character or numeric data?
Regards,
Amir.
It originally was numeric and I converted the data to character data. I was able to add a leading zero by doing this but I also need to add a trailing zero as well.
example: '3' to '030'
Hi,
Consider either multiplying the numeric by 10 before converting it to character, or when it is character consider using the cats() function, e.g.:
var2=cats(var1,'0');
Regards,
Amir.
You might want to consider adding both the leading and trailing zero in one step:
charvar = put(numvar * 10, z3.);
I have a similar problem. When I merge number with decimals, the decimals that are zero get cut off. For example, merging 2.500 and 6.050 would produce 2.5-6.05. How do I get the program to stop cutting off the zeroes and output 2.500-6.050?
The values aren't cut off it is a result of internal numeric storage.
You don't show how you have attempted to create your 2.500 - 6.050 but the likeliest answer is going to involve a format that displays at a given precision.
For example a value of 2.5 will display at 2.500 when using something like F6.3 which forces every appearance to show 3 values to the right of a decimal point.
One way to create a string of your example
data _null_;
x= 2.5;
y= 6.05;
result = catx(' - ',put(x,7.3),put (y,7.3));
put result;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.