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

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

1 ACCEPTED SOLUTION

Accepted Solutions
ed_sas_member
Meteorite | Level 14

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,

View solution in original post

3 REPLIES 3
ed_sas_member
Meteorite | Level 14

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,

Solly7
Pyrite | Level 9

thank you so much

novinosrin
Tourmaline | Level 20

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;

 

 

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1100 views
  • 2 likes
  • 3 in conversation