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

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.

 

swathiprasad_1-1643937101018.png

 

 

 

 

example of data:F0F0F0F0C1F1F0F5F0F0F0F0F0F9F240D5404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040D72020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020

 

how to convert this hex to ascii/char .

 

Request help on this!

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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?

View solution in original post

3 REPLIES 3
SASKiwi
PROC Star

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?

sfffdg
Obsidian | Level 7
Yeah ,I am signing in to a unix box through remote session , then running a DB2 query there.

I have checked the DB2 ,its data type is varchar(2000) for bit data.Yes the data looks the same in db2 as well.
Tom
Super User Tom
Super User

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?

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

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
  • 3 replies
  • 795 views
  • 0 likes
  • 3 in conversation