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

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 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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 

View solution in original post

4 REPLIES 4
Kurt_Bremser
Super User

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 
Pon1
Calcite | Level 5

Hi 

 

 

 

 

Kurt_Bremser
Super User

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.

Pon1
Calcite | Level 5

Hi 

 

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
  • 4 replies
  • 5158 views
  • 0 likes
  • 2 in conversation