BookmarkSubscribeRSS Feed
DandarahZ
Obsidian | Level 7

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?

 

4 REPLIES 4
Astounding
PROC Star

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.

nwinkler
Calcite | Level 5
I believe this should be marked as the answer.
FredrikE
Rhodochrosite | Level 12

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

PetriRoine
Pyrite | Level 9

@DandarahZ 

 

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.

Capture11.PNG

 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.

Capture12.PNG

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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Tips for filtering data sources in SAS Visual Analytics

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.

Discussion stats
  • 4 replies
  • 810 views
  • 5 likes
  • 5 in conversation