Hi,
How to convert packed Hexa Decimal value to a character value in sas .
The Background is ,Using the below query I am downloading from IBM x86.
rsubmit;
%macro DownloadTables (inSchema,intable,out);
* Download tables *;
%include 'macros/connect.sas';
options validvarname=any;
proc sql;
connect to db2 as pscon(
user=&user
password=&password
database=&database
);
create table &out. as
select * from connection to pscon (
select
MH_Data
from &inSchema..&intable.
where date(TIMESTAMP) >= current date - 30 days
WITH UR
) ;
disconnect from pscon;
quit;
%mend;
%DownloadTables (inschema,intable,outtable);
endrsubmit;
for some reason , in sas it is hex format as below.
example of data:F0F0F0F0C1F1F0F5F0F0F0F0F0F9F240D5404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040D72020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020
how to convert this hex to ascii/char .
Request help on this!
I don't see any packed decimal there.
It just looks like EBCIDIC. All of those 40 codes are spaces in EBCIDIC. Then the end of the string looks like 20 codes where are spaces in ASCII. It is like you copied the EBCIDIC string into a longer SAS variable, so it was padded with spaces (just as SAS does with all character variables.)
So your posted example looks like this:
14 data check; 15 string='F0F0F0F0C1F1F0F5F0F0F0F0F0F9F240D540'x; 16 format string $hex.; 17 length = length(string); 18 ASCII = input(string,$ebcdic18.); 19 put (string length ascii) (=/); 20 run; string=F0F0F0F0C1F1F0F5F0F0F0F0F0F9F240D540 length=18 ASCII=0000A1050000092 N
Is that what you expected?
Judging by your program, you appear to be signing on to a mainframe SAS session, then running a DB2 query there. What is the data type of the column being queried in DB2? Also run a PROC CONTENTS on the SAS dataset created by the query on the mainframe before it is downloaded and post the results. Does the data look the same in the mainframe SAS session as it does once you have downloaded it?
I don't see any packed decimal there.
It just looks like EBCIDIC. All of those 40 codes are spaces in EBCIDIC. Then the end of the string looks like 20 codes where are spaces in ASCII. It is like you copied the EBCIDIC string into a longer SAS variable, so it was padded with spaces (just as SAS does with all character variables.)
So your posted example looks like this:
14 data check; 15 string='F0F0F0F0C1F1F0F5F0F0F0F0F0F9F240D540'x; 16 format string $hex.; 17 length = length(string); 18 ASCII = input(string,$ebcdic18.); 19 put (string length ascii) (=/); 20 run; string=F0F0F0F0C1F1F0F5F0F0F0F0F0F9F240D540 length=18 ASCII=0000A1050000092 N
Is that what you expected?
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.