BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
alepage
Barite | Level 11

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

View solution in original post

5 REPLIES 5
Tom
Super User Tom
Super User

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.

alepage
Barite | Level 11
The information I have, is that the original file will use the EBCIDC format and that the variable will be 9 characters long. Then I need to convert it to numeric format like 99.123456

How do we do that?
Tom
Super User Tom
Super User

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;
alepage
Barite | Level 11
Hello Tom,
Based on your above mentioned answer, I have try a little script to help me to understand. So, value is what I would like to obtain at the end. So, ebcidic_val=put(value,s370ff9.6), will convert my value to ùùKñòóôõö . This converted value is what I probably have into myfile @235. Then, the input statement
(newvar1 = input(ebcidic_val,$EBCDIC9. ); convert this strange value into a character. Then we can use another input statement or a format statement to convert it a decimal value, like input(string, 9.6) or format newvar2 9.6

Thank for your help.

data test3;
format newvar2 9.6 ;
value=99.123456;
ebcidic_val=put(value,s370ff9.6);
newvar1 = input(ebcidic_val,$EBCDIC9. );
newvar2=newvar1;
run;
Tom
Super User Tom
Super User

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

 

 

 

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1079 views
  • 2 likes
  • 2 in conversation