what does this format means, I read the sas documentation and dont get it
S370FPD9.0
if the variable apple come in from in input statment like this
input apple S370FPD9. (after an infile ".../.../amb.txt" statement)
what exactly is its format?
Take a look a the documentation
Writes packed decimal data in IBM mainframe format.
Use S370FPD w. d in other operating environments to write packed decimal data in the same format as on an IBM mainframe computer.
Value of
x |
Result
|
---|---|
128 |
0000128C |
- Cheers -
The informat has no effect on the display format. It just controls how data is read into the SAS environment from an external source.
First of all, follow Maxim 1 and read the documentation: S370FPDw.d Informat
The Packed Decimal format is used on IBM mainframes to store numbers. Each digit is stored in 4 bits, and the last 4-bit nibble is used for the sign. Your informat with a length of 9, without decimals, will therefore read an integer number with at most 17 digits.
Your first problem is that this code is using an INFORMAT and not a FORMAT. So look for the documentation on the informat, not on the format.
Remember: FORMATs convert values into text. INFORMATs convert text into values.
So that informat specification of S370FPD9.0 says to read 9 bytes from the text file and interpret it as a binary encoded decimal value using on System 370 computers (IBM Mainframes). The zero means that it will divide the result by 10 to the power 0 (which is just 1) to indicate where the implied decimal point will be placed. So it is read an integer value.
A packed decimal value stores one decimal digit in each nibble. (An 8 bit byte consists of two 4 bit nibbles). This means that you are reading BINARY data from that text file and converting it into an integer number. So if you want to check your resulting number against the value in the text file and see what it is doing you will need to print those 9 bytes using the $HEX format instead of normal $ format so you can see what each nibble contains.
The only tricky part is the last nibble is used to indicate the sign of the number.
Run some test to see what S370FPD format and informat do.
data test;
do number=-1,0,1,1234,123456789 ;
string = put(number,s370fpd9.0);
format string $hex18.;
number2 = input(string,s370fpd9.0);
output;
end;
run;
proc print;
run;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
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.