- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I am trying to convert the characters to hexadecimal. Here you have an example.
I have a variable named Model , where model= 3096-712 which is a string.
I need to assign it to a new variaable called V1_hex = '3096'x where it should take the first four characters of model.
Please help me with some solution.
Thank you,
Regards,
Pon1.
I tried using this code
DATA MYDATA;
format V1_HA V2_CHA $Char8.;
V1_CHA='3096-712';
V2_CHA='3096-708';
run;
Data Outdata;
format V1_Hex V2_Hex $hex4.;
V1_Hex=put(Substr(V1_CHA,1,4),$hex4.);
V2_Hex=put(SubStr(V2_CHA,1,4),$hex4.);
run;
proc Print Data=outdata;
run
//*
I go the output as
.............................................
The SAS System
Obs V1_Hex V2_Hex V1_CHA V2_CHA
1 F4 F4 . .
Help me to code for abtaining the
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Use the input() function:
DATA MYDATA;
format V1_CHA V2_CHA $Char8.;
V1_CHA='3096-712';
V2_CHA='3096-708';
run;
Data Outdata;
set mydata;
format V1_Hex V2_Hex $hex4.;
V1_Hex = input(substr(V1_CHA,1,4),$hex4.);
V2_Hex = input(SubStr(V2_CHA,1,4),$hex4.);
run;
proc print data=outdata noobs;
run;
Result:
V1_CHA V2_CHA V1_Hex V2_Hex 3096-712 3096-708 3096 3096
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Use the input() function:
DATA MYDATA;
format V1_CHA V2_CHA $Char8.;
V1_CHA='3096-712';
V2_CHA='3096-708';
run;
Data Outdata;
set mydata;
format V1_Hex V2_Hex $hex4.;
V1_Hex = input(substr(V1_CHA,1,4),$hex4.);
V2_Hex = input(SubStr(V2_CHA,1,4),$hex4.);
run;
proc print data=outdata noobs;
run;
Result:
V1_CHA V2_CHA V1_Hex V2_Hex 3096-712 3096-708 3096 3096
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi KurtBremser,
Greetings!!
Thank you, for immediate response. I used the above code and got the result as
The SAS System
V1_Hex V2_Hex V1_CHA V2_CHA
4040 4040 . .
I not able to see the actual characters as output. for V1_CHA and V2_CHA also the hexadecimal values.
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Please run my code as posted. Your code misses the necessary set statement. You can see this in the log, it will complain about uninitialized variables.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi KurtBremser,
I apologize for my mistake. I have missed the set statement. I thank you for the solution provided. It works fine.
thanks a lot.
Thank you,
Regards,
Pon1