Im currently working on a project that requires a dashboard. However, during the data collection process, majority of the values are saved in string format where as i need certain values in numerical format. Is there a way for me to convert the values from string format to Integer?
On the surface it's easy to do, but you need to use a new variable name:
newvar = input(oldvar, 8.);
A few additional considerations ...
There may be a reason why the values were stored as strings. For example, perhaps the data contains occasional instances of "N/A". Those would give you a message about invalid numeric data if you attempt to convert them to numeric. So you do have to decide what the outcome should be in that situation.
If the length of the character variables is more than $8, you may need to use a wider width, such as:
newvar = input(oldvar, 16.);
Finally, if you must keep the original variable names for some reason, you could do it in this fashion:
data want; set have; newvar = input(oldvar, 8.); drop oldvar; rename newvar = oldvar; run;
Unfortunately, you do need to add to the program for each variable that you want to process in this way.
Although the preferable way is to handle this before uploading data to Visual Analytics, one can also handle this in VA directly. The correct Operator is Parse.
And here you can see how your new variable is truly a number. I left decimals there so it's easier to see the difference from Text.
Sometimes the number is part of string with alphabets included such as A123 or Metal123. In these cases you can first apply Substring Operator and then utilize Parse. I hope this helps.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
See how to use one filter for multiple data sources by mapping your data from SAS’ Alexandria McCall.
Find more tutorials on the SAS Users YouTube channel.