Hi, i need help in removing characters from ninth value and remain with the first 8 characters. See below dummy data
work.names
Data have Data Want
matomese@rrrtrtr matomese
lucozade1rtrrrere lucozade
sollyseb+rytryr sollyseb
Hi @Solly7
You can try this:
Data have ;
input var1 $30.;
datalines;
matomese@rrrtrtr
lucozade1rtrrrere
sollyseb+rytryr
;
run;
/* If the length of the word to extract is always 8 */
data want;
set have;
var2 = substr(var1,1,8);
run;
/* Otherwise you can search for the first word delimited by any character which is not in the alphabet */
data want;
set have;
var2 = scan(var1,1,"","ak");
run;
NB: information on modifiers for the SCAN() function (like "ak") is available on: https://documentation.sas.com/?docsetId=ds2ref&docsetTarget=p13adatt2vvhcxn1ext6w6eet24p.htm&docsetV...
Best,
Hi @Solly7
You can try this:
Data have ;
input var1 $30.;
datalines;
matomese@rrrtrtr
lucozade1rtrrrere
sollyseb+rytryr
;
run;
/* If the length of the word to extract is always 8 */
data want;
set have;
var2 = substr(var1,1,8);
run;
/* Otherwise you can search for the first word delimited by any character which is not in the alphabet */
data want;
set have;
var2 = scan(var1,1,"","ak");
run;
NB: information on modifiers for the SCAN() function (like "ak") is available on: https://documentation.sas.com/?docsetId=ds2ref&docsetTarget=p13adatt2vvhcxn1ext6w6eet24p.htm&docsetV...
Best,
thank you so much
Hi @Solly7 If length of Var2 is going to be 8, all you need is define a compile time LENGTH statement and not bother with anything else .
For Example
Data have ;
input var1 $30.;
datalines;
matomese@rrrtrtr
lucozade1rtrrrere
sollyseb+rytryr
;
run;
data want;
set have;
length var2 $8;
var2=var1;
run;
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.