BookmarkSubscribeRSS Feed
HeatherNewton
Quartz | Level 8

hi what does the following do

 

 

/* am='6223460604630016' */

put (am,z19.) as ambs 

 

 

6 REPLIES 6
PeterClemmensen
Tourmaline | Level 20

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.

PaigeMiller
Diamond | Level 26

@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
Kurt_Bremser
Super User

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.

HeatherNewton
Quartz | Level 8

What does z19. Means

 

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

Tom
Super User Tom
Super User

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.

 

ballardw
Super User

@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.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 6 replies
  • 891 views
  • 0 likes
  • 6 in conversation