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
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
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
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.
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.
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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.