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


I am looking  to extract from a code in a field the last only three characters - am trying to do this in SAS® Data Studio - Prepare Data.

Using data prep from SAS Viya 3.5

 

Code in the field can look something like this      265265414TGA

And I want to extract/include only the last 3 characters TGA

 

I dont want to code this in if possible rather use the options available

Any suggestions - thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Sam_SAS
SAS Employee

Hello,

 

You can do this directly in VA by creating a calculated item with the Substring() operator. If the length of the value is not always the same, you can use GetLength() to determine the length of the value.

 

Those operators are documented here:

https://go.documentation.sas.com/doc/en/vacdc/v_008/vareportdata/p0dovqqp325peyn1dpijpxxmwj83.htm#n1...

 

So to get the last three characters from the "Name" column you would do something like,

 

Substring('Name'n, ( GetLength('Name'n) - 2 ), 3)

 

I'm sure this can also be done in Data Studio, but I can't tell you offhand how to do it.

View solution in original post

2 REPLIES 2
Sam_SAS
SAS Employee

Hello,

 

You can do this directly in VA by creating a calculated item with the Substring() operator. If the length of the value is not always the same, you can use GetLength() to determine the length of the value.

 

Those operators are documented here:

https://go.documentation.sas.com/doc/en/vacdc/v_008/vareportdata/p0dovqqp325peyn1dpijpxxmwj83.htm#n1...

 

So to get the last three characters from the "Name" column you would do something like,

 

Substring('Name'n, ( GetLength('Name'n) - 2 ), 3)

 

I'm sure this can also be done in Data Studio, but I can't tell you offhand how to do it.

PaulTHR
Fluorite | Level 6
Thanks very much - that will do for me.

Thanks

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 2 replies
  • 382 views
  • 1 like
  • 2 in conversation