Hello,
I am not very familliar with ebcidic format and I need your help
we have a zip file that will be unzip on our work environment that we have an old program like below. The new variable will be at position 2250, and will be 9 characters long.
I need to convert this 9 characters variable into a numeric 9.6 , so I believe 9 number long including the comma and 6 digits after the number.
So I wonder if I could replace the input line @2250 NEWVARIABLE $EBCDIC9.
by @2250 NEWVARIABLE S370FZD9.6 to have it converted directly to the good format?
If not, what should I do?
Data autoprm;
length company $1 ...;
INFILE EBCDIC missover;
INPUT ...
@2250 NEWVARIABLE $EBCDIC9. /*S370FZD9.6*/
;
FILE ASCII;
PUT @209 INCEPTIONDATE PD5.
...
;
... FEW IF STATEMENTS
OUTPUT autoprm;
run;
So if the line original contained the text string '99.123456' then it should have the 9 bytes:
F9 F9 4B F1 F2 F3 F4 F5 F6
So read with $EBCDIC9. informat. Then use the INPUT() function to convert that into an actual number.
So if the 9 bytes start in position 235 on the line the code might look something like this.
data want;
infile 'myfile' ;
input @235 string $ebcdic9. ;
number = input(string,9.);
run;
EBCDIC and packed decimal are two different things.
EBCDIC means the field is text, but the letters just use different codes. So the digit zero is represented by 'F0'X instead of the '30'x used by ASCII.
So to if the value stored was 9 digits like '123456789' then that means to actual hex codes for the values stored is 'F0F1F2....' in EBCDIC or '303132....' in ASCII. So first read the values using $EBCDIC to get ASCII version of the string and then use INPUT() with normal informat like 9. to convert the character digits into a number. If the string does not actually include a physical period to represent the decimal place then use informat 9.6 and SAS will divide the number by 10**6 to put the decimal point at the right place.
Packed Decimal means the field is binary instead of text. So you can just read the field directly with the appropriate informat. If you do want to read the field into a character string first then use $CHAR informat because you do NOT want to do an EBCDIC to ASCII conversion on the binary codes in that field.
So if the line original contained the text string '99.123456' then it should have the 9 bytes:
F9 F9 4B F1 F2 F3 F4 F5 F6
So read with $EBCDIC9. informat. Then use the INPUT() function to convert that into an actual number.
So if the 9 bytes start in position 235 on the line the code might look something like this.
data want;
infile 'myfile' ;
input @235 string $ebcdic9. ;
number = input(string,9.);
run;
Yes.
You can use the S370FF informat to convert directly from EBCDIC to numbers without having to first read it as a character string.
The meaning of the decimal part on an informat is totally different than the meaning on a format. Do not include the 6 after the decimal point on the informat unless you want values that do not include a period to be divided by 10**6.
data test3;
value1=99.123456;
string1 = put(value1,9.6);
ebcdic1 = put(string1,$ebcdic9.);
ebcdic2 = put(value1,s370ff9.6);
string2 = input(ebcdic1,$ebcdic9.);
esame = ebcdic1 = ebcdic2;
asame = string1 = string2;
value2= input(string2,9.);
value3= input(ebcdic1,s370ff9.);
format string: $quote. ebcdic: $hex. ;
put (_all_) (=/);
run;
value1=99.123456 string1="99.123456" ebcdic1=F9F94BF1F2F3F4F5F6 ebcdic2=F9F94BF1F2F3F4F5F6 string2="99.123456" esame=1 asame=1 value2=99.123456 value3=99.123456
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.