Quartz | Level 8

## z19.

hi what does the following do

/* am='6223460604630016' */

put (am,z19.) as ambs

6 REPLIES 6
Super User

## Re: z19.

It creates a character variable ambs that is the value of am with leading zeros up to a length of 19, using the Z Format.

Diamond | Level 26

## Re: z19.

@HeatherNewton wrote:

hi what does the following do

/* am='6223460604630016' */

put (am,z19.) as ambs

The best answer is for you to try it and see what happens.

--
Paige Miller
Super User

## Re: z19.

Looks like an attempt to fix the mistake of storing codes as a number, but this is bound to fail anyway, see this example:

data _null_;
am = 9223460604630017;
format am 19.;
ambs = put(am,z19.);
put am= / ambs=;
run;

Run it, and read the log.

Quartz | Level 8

## Re: z19.

What does z19. Means

i thought it mean to add 3 zero in front so becomes 19 digits, am I right.

Super User

## Re: z19.

Z19. is a format specification.  Just like DATE9. is a format specification.

Z is the name of the format.  19 is the width you want it to use to display the value.

You use the Z format to display integers with leading zeros.  So whatever magnitude the value has it will always print with 19 digits adding zeros in the front if needed.

But remember that SAS stores all numbers as 64 bit binary floating point values.  So the largest integer it can store before you start seeing gaps is smaller than 19 digits long.

9077   data _null_;
9078     exactint = constant('exactint');
9079     put exactint Z19.;
9080   run;

0009007199254740992

So if you have any numbers that are larger than 9,007,199,254,740,992 then you cannot count on all of those digits being properly stored as a number.

That is one reason why it would have been better to have created the variable as character to begin with, to avoid loss of precision in the value.

Super User

## Re: z19.

@HeatherNewton wrote:

What does z19. Means

i thought it mean to add 3 zero in front so becomes 19 digits, am I right.

Not necessarily if the variable is defined a CHARACTER as shown in your example. A numeric format cannot be used with a Character value and would result in an ERROR of the form "Format \$Z not found". Unless somewhere you have a custom character format named Z in your current format search path. At which point I have no idea what the result might be as we would need the definition of that format.

Discussion stats
• 6 replies
• 149 views
• 0 likes
• 6 in conversation