Hello,
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.
Hi!
If in VA tou can use functions like "TreatAs" and "Format" to change type. You will need to create calculated variables using these functions 🙂
//Fredrik
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.
Best regards,
Petri
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.