BookmarkSubscribeRSS Feed
Patty
Calcite | Level 5

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.

6 REPLIES 6
Amir
PROC Star

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.

Patty
Calcite | Level 5

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'

Amir
PROC Star

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.

Astounding
PROC Star

You might want to consider adding both the leading and trailing zero in one step:

charvar = put(numvar * 10, z3.);

Haris
Lapis Lazuli | Level 10

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?

ballardw
Super User

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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 6 replies
  • 13334 views
  • 3 likes
  • 5 in conversation