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

Hello,

 

I am trying to find documentation on why one should not mulitply one to a character variable to convert character to numeric (unless its really needed).  I found some information on the paper 248-2012 on page 9 about it; however, I know that there is more information warning others not to perform this method other than saying its bad practice or sloppy coding. 

 

Any resources about not using this method is greatly apprecated.

 

Best

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

There is no other reason other than bad practice and sloppy coding.

 

Usually these types of things will mask errors that you won't notice or it will be hard to find actual issues when you have them if you get used to seeing these NOTES and ignoring them. So not coding in this manner will help you in the long run. 

 


@yo1 wrote:

Hello,

 

I am trying to find documentation on why one should not mulitply one to a character variable to convert character to numeric (unless its really needed).  I found some information on the paper 248-2012 on page 9 about it; however, I know that there is more information warning others not to perform this method other than saying its bad practice or sloppy coding. 

 

Any resources about not using this method is greatly apprecated.

 

Best


 

 

View solution in original post

6 REPLIES 6
ballardw
Super User

Personally my opinion is it indicates a lack of understanding of the data involved. If a variable should be numeric then it should be numeric all the time.

 

Also in some shops there are rules about data standards and messages about type conversion occuring in the log indicate that the standards are not followed.

 

And in general coding terrms how much difference is there really between

numval = val*1;

and

numval = input(val, best.);

yo1
Obsidian | Level 7 yo1
Obsidian | Level 7

Hello Ballardw,

 

Thank you for your response. I agree with you in that some shops have rules about data standards and that should be the case especially when a specific data products are looked at carefully by many.   However, I disagree with the idea that when a variable is numeric it should stay numeric. I have come across situations where a specific key variable (which is numeric) used in merging tables needs to be converted.  

 

I think that the numval = input(val, best.); option of converting is the optimal choice; however, I have come across a situation where this type of conversion is not the best choice.

 

For example, when an algorithm   produces a value that is an imaginary number.   This element needs to be changed so that the rest of the data series can be used for processing.

 

Therefore the numval = val*1; is better method to use.   So I would advocate using numval = val*1; method of converting variable types in cases where there is no other option.

 

many thanks

 

 

 

Reeza
Super User

@yo1 wrote:

 

I think that the numval = input(val, best.); option of converting is the optimal choice; however, I have come across a situation where this type of conversion is not the best choice.

 

For example, when an algorithm produces a value that is an imaginary number. This element needs to be changed so that the rest of the data series can be used for processing.

  


How can you be sure only imaginary numbers are being converted and you don't have any other issues in your algorithm if you multiply by 1? 

 

 

 

yo1
Obsidian | Level 7 yo1
Obsidian | Level 7
This was a rare case that we came across and that variable in question converted to numeric and the imaginary number changed (I forgot what value it turned into). The conversion took place after the data was processed in the data step.
Reeza
Super User

There is no other reason other than bad practice and sloppy coding.

 

Usually these types of things will mask errors that you won't notice or it will be hard to find actual issues when you have them if you get used to seeing these NOTES and ignoring them. So not coding in this manner will help you in the long run. 

 


@yo1 wrote:

Hello,

 

I am trying to find documentation on why one should not mulitply one to a character variable to convert character to numeric (unless its really needed).  I found some information on the paper 248-2012 on page 9 about it; however, I know that there is more information warning others not to perform this method other than saying its bad practice or sloppy coding. 

 

Any resources about not using this method is greatly apprecated.

 

Best


 

 

yo1
Obsidian | Level 7 yo1
Obsidian | Level 7

Hello Reeza,

 

Thank you for your response.  I accepted it as the solution.  I am still looking for a document that goes into greater detail about the subject.  However, you have brought about a good point about the notes appearing in the log.

 

Massive thanks.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 6 replies
  • 932 views
  • 2 likes
  • 3 in conversation