DATA Step, Macro, Functions and more

Smallest values with packed data

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 89
Accepted Solution

Smallest values with packed data

Most text books say that the smallest values are the missing values: ""(character) and .(numeric)

Apparently, this applies only to regular unpacked data.

The byte that represents packed data seems to be smaller than the usual missing ""(character) value.

Such bytes don't have any meaning and can appear to be symbols like:

Null, start of heading, start of text, end of text, punch off, horizontal tab...

I thought that such symbols would be greater than missing "", but apparently they're less than or equal to missing.

This is in z/OS EBCDIC using SAS 9.2, but I expect similar results in Windows ASCII.

Specific example: trying to read a packed decimal field conditionally:

   if substr(_infile_,1,3)>'' then input @1 var1  pd3. ;

This line doesn't produce an error, but the IF expression is always false, so it looks like packed bytes are less than or equal to missing.

Please correct me if I'm wrong.


Accepted Solutions
Solution
‎06-20-2014 07:55 PM
Super User
Super User
Posts: 7,060

Re: Smallest values with packed data

MISSING does not apply for CHARACTER strings.

Your IF statement is testing if the ASCII codes for the first three characters in the input stream is larger than the ASCII code for a single space.

So if the first byte of your binary packed decimal value happens to have a hexadecimal value less than '20'X then the IF will be false.

If I store 10 into PD3. format I get the value '000010'x. This is definitely less than ' ' as binary zero that is in the first byte is less than the binary 32 stored as the value of space.

If I try to store numeric missing into PD3. format I get the value '800000'x.

View solution in original post


All Replies
Solution
‎06-20-2014 07:55 PM
Super User
Super User
Posts: 7,060

Re: Smallest values with packed data

MISSING does not apply for CHARACTER strings.

Your IF statement is testing if the ASCII codes for the first three characters in the input stream is larger than the ASCII code for a single space.

So if the first byte of your binary packed decimal value happens to have a hexadecimal value less than '20'X then the IF will be false.

If I store 10 into PD3. format I get the value '000010'x. This is definitely less than ' ' as binary zero that is in the first byte is less than the binary 32 stored as the value of space.

If I try to store numeric missing into PD3. format I get the value '800000'x.

Frequent Contributor
Posts: 89

Re: Smallest values with packed data

The Definition of Missing Values recognizes "missing character value as a blank space", so I would rather say that SAS considers the space character " " to be equivalent to an empty character string "".

This is the part that I forgot. Thank you for reminding me about this.

If "" = " ", and " "='20'x in ASCII and '40'x in EBCDIC, then there are many opportunities for some packed bytes to be smaller than '20'x and even more opportunities to be smaller than '40'x.

Also, I should've read the last 2 sentences of Order of Missing Values in SAS Help.

In my specific example, the only thing that I'm trying to avoid is spaces, so I should've excluded only spaces instead of a range of characters:

if substr(_infile_,1,3) ne '' then input @1 var1  pd3. ;

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 180 views
  • 0 likes
  • 2 in conversation