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

I need to input two hexadecimal bytes and manipulate the 4 nibbles that are contained within.  For example, the two bytes in the file contain '13BC'x.  The first nibble is '1', the second nibble is '3', the third nibble is 'B' and the fourth nibble is 'C'.  Due to some *creative* programming, I need to isolate the first nibble and interpret it and then isolate the last three nibbles and interpret them.  If the 4 nibbles can be converted to a string, I can proceed from there.

 

Does anyone know which informat and/or functions I would use to produce a 4 char string of hex characters that I can then manipulate?

 

Note:  I am a long time mainframe base SAS user, but first time question asker!  Thanks in advance for any hints, suggestions or outright answers!

1 ACCEPTED SOLUTION
4 REPLIES 4
MarkATremel
Obsidian | Level 7

Thank you for your response.  However, before I try this, I notice that the SAS documentation says that for this informat, this is the behavior, but I would need it to write 6C6C to the SAS log.

Example

data test;                  
   name='6C6C';                    
   name2=input(name,$hex4.);       
run;                               

SAS writes the following output to the log:

11
ballardw
Super User

When you use an INPUT then you are using an INFORMAT to read text into numeric values. You said that you already have a hex value.

 

See the difference with this which uses an existing Hex value and creates the desired character value:

data test;                  
   name='6C6C'x;                    
   name2=put(name,$hex4.);       
run;        

PUT uses the FORMAT to display the value.

 

 


@MarkATremel wrote:

Thank you for your response.  However, before I try this, I notice that the SAS documentation says that for this informat, this is the behavior, but I would need it to write 6C6C to the SAS log.

Example

data test;                  
   name='6C6C';                    
   name2=input(name,$hex4.);       
run;                               

SAS writes the following output to the log:

11

 

MarkATremel
Obsidian | Level 7

More detail:  I hope this helps to explain my situation better.

 

INPUT...

@0553 SUSPCD01 $HEX4.
@0555 SUSPCD02 $HEX4.
@0557 SUSPCD03 $HEX4.

...

 

NOTE: Invalid data for SUSPCD01 in line 2 553-556.
NOTE: Invalid data for SUSPCD02 in line 2 555-558.
NOTE: Invalid data for SUSPCD03 in line 2 557-560.
RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+

501 ..................................................... . . ...........
ZONE 00000000000000000000000000000000000000000000000000001B1B1B00000000000
NUMR 00000000000000000000000000000000000000000000000000003CBCBC00000000000

 

SUSPCD01= SUSPCD02= SUSPCD03=

 

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 4 replies
  • 1039 views
  • 1 like
  • 3 in conversation