Hi there,
I have a simple query i want to execute and I'm finding it hard, as I'm new to this.
I have a list off "Agreement" numbers but they have character and numeric values and I just want to extract the characters into a new column.
Example of "Agreement" number:
BAU123455L - I only need BAU
below is the code I used but getting no results.
if substr(left(Agreement),3) = 'BRN'
For future note, good idea to post test data (form of a datastep) and required output, so we can see input and output. Something like:
want=substr(compress(agreement,"","ka"),1,3);
Should work.
Something like:
want=compress(agreement,"","ka");
You can find details of the options k and a in the documentation:
http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000212246.htm
Hi RW9,
Thank you for your quick response - it works but I only want the first 3 characters - this is bring the letter at the end as well and I just need the first 3 characters?
For future note, good idea to post test data (form of a datastep) and required output, so we can see input and output. Something like:
want=substr(compress(agreement,"","ka"),1,3);
Should work.
Thank you so much RW9.
This has helped, in future I will share more info. this was my first time I submitted a question and you guys are very helpful.
Thank you again.
Glad you got a good answer! Another suggestion...in the future, give your post a meaningful title, something like what RW9 edited it to. It makes it easer to decide whether to take a look at it or not.
Tom
Just define a new variable with the function you are using. Check the example below.
data test;
agreement = ' BAU123455L';
newcol = substr(left(agreement),1,3);
run;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.