- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I have two variables that are internally stored as two bytes of hex data each. I need to create another variable from these two, such that the new variable is a character concatenation of the two, with the equivalent hexadecimal characters, in this case 8 characters.
I've tried
V1V2_CHAR = CAT(V1_HEX, V2_HEX);
FORMAT V1V2_CHAR $CHAR4. ;
but the variable still prints in hex (non-printable on the screen) but a hex display shows it.
I admittedly only use SAS on rare occasions, so pardon my newbi-ness..
Thanks!
Rod
PS. This is SAS on z/OS.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello Rod,
Here's an example (tested on a Windows machine):
data have;
v1_hex='030B'x;
v2_hex='4041'x;
run;
data want;
set have;
v1v2_char=put(v1_hex||v2_hex, $hex8.);
run; /* Result: 030B4041 */
If V1_HEX and V2_HEX are character variables of length >2 (i.e. contain trailing blanks), you'll want to replace the assignment statement with
v1v2_char=put(cats(v1_hex, v2_hex), $hex8.);
unless you see a risk that removing leading and trailing blanks (by the CATS function) could truncate any of the two variables (because they happen to contain a blank as the first or second character). In the latter case, you can use:
v1v2_char=put(put(v1_hex,$2.)||put(v2_hex,$2.), $hex8.);
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello Rod,
Here's an example (tested on a Windows machine):
data have;
v1_hex='030B'x;
v2_hex='4041'x;
run;
data want;
set have;
v1v2_char=put(v1_hex||v2_hex, $hex8.);
run; /* Result: 030B4041 */
If V1_HEX and V2_HEX are character variables of length >2 (i.e. contain trailing blanks), you'll want to replace the assignment statement with
v1v2_char=put(cats(v1_hex, v2_hex), $hex8.);
unless you see a risk that removing leading and trailing blanks (by the CATS function) could truncate any of the two variables (because they happen to contain a blank as the first or second character). In the latter case, you can use:
v1v2_char=put(put(v1_hex,$2.)||put(v2_hex,$2.), $hex8.);
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Given your newness to SAS, I would suggest checking your assumptions about what these variables actually contain. It's simple enough to do that:
data _null_;
set have;
put v1_hex @4 $hex4. @10 v2_hex @13 v2_hex $hex4.;
stop;
run;
The solution changes depending on what text is actually in the original variables.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks to all who responded! The PUT was what I was missing and the recommendations solved the problem.