| Date: | Tue, 6 Jul 2004 05:59:22 -0700 |
| Reply-To: | Bart Heinsius <eombah@HOTMAIL.COM> |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | Bart Heinsius <eombah@HOTMAIL.COM> |
| Organization: | http://groups.google.com |
| Subject: | Re: long string -> hex -> decimal |
| Content-Type: | text/plain; charset=ISO-8859-1 |
Ya,
Your code contains a little error.
Try running it with D4427FEA0179008B.
Your code gives:
D4427FEA0179008B
15294927927502700544
24707211
02700544
027407755
0
15294927
1529492727407755
but the answer should be:
15294927927527407755
It's due to the line:
a5c=substr(compress(a1c),1,length(compress(a2c)));
Replacing it with
a5c=substr(compress(a1c),1,length(compress(a1c))-length(compress(a2c)));
fixes it. So, for the archive, the complete code is:
data a;
set fap.gl_acct_list_lines(firstobs=10 obs=10);
a=put(GL_ELEMENT_RANGE,$hex16.);
a1n=input(substr(a,1,8),hex8.)*16**8;
a1c=put(input(substr(a,1,8),hex8.)*16**8,best32.);
a2n=input(substr(a,9,8),hex8.);
a2c=put(input(substr(a,9,8),hex8.),best32.);
put a / a1c $char32. / a2c $char32.;
a3c=substr(compress(a1c),length(compress(a1c))-length(compress(a2c))+1);
a3n=input(a3c,best32.);
put a3c $char32. -r;
a4n=a2n+a3n;
a4c=put(a4n,best32.);
if length(compress(a4c))=length(compress(a3c)) then
a4c='0'!!compress(a4c);
carryover=substr(compress(a4c),1,length(compress(a4c))-length(compress(a3c)));
put a4c $char32. -r;
put carryover;
a5c=substr(compress(a1c),1,length(compress(a1c))-length(compress(a2c)));
put a5c $char32. -r;
final=put(input(a5c,best32.)+input(carryover,best.),best32.)||substr(compress(a4c),2);
put final;
run;
Cheers,
Bart.
|