I have a data set named names with only one variable x.
x
* '''[[Nick]]'''
* [[KK Circle]]
* [[Spenser]]
||-
* Cool
||
Name
I want to create a new dataset with two variables, the first being the whole old line, and the second variable with only the names.
And each like should be only the line with character in it.
Like:
x newX
* '''[[Nick]]''' Nick
* [[KK Circle]] KK Circle
* [[Spenser]] Spenser
* Cool Cool
Name Name
I tried
newX=compress(x ,";{|-*![=],");
but I couldn't get rid of the "" on the line Nick.
Might not need to use all of COMPRESS, INDEX, LEFT, TRIM, but these might be useful.
Thank you.
The example data you show for
* '''[[Nick]]'''
is 3 single quotes.
which would work with
data junk; x="* '''[[Nick]]'''"; newX=compress(x ,";{|-*![=],'"); run;
If you need to find one of the quote character you can double in the search string such as
newX=compress(x ,";{|-*![=]"",'");
I placed the double quote to use in the search away from the quotes used to delimit the string so you can read it a bit more clearly. Note that in the editor a single " in the middle would show as an unbalance quote by having one or more characters appear differently than the quoted string. With the doubled character the entire string appears and is treated as a single string.
The example data you show for
* '''[[Nick]]'''
is 3 single quotes.
which would work with
data junk; x="* '''[[Nick]]'''"; newX=compress(x ,";{|-*![=],'"); run;
If you need to find one of the quote character you can double in the search string such as
newX=compress(x ,";{|-*![=]"",'");
I placed the double quote to use in the search away from the quotes used to delimit the string so you can read it a bit more clearly. Note that in the editor a single " in the middle would show as an unbalance quote by having one or more characters appear differently than the quoted string. With the doubled character the entire string appears and is treated as a single string.
data have;
input x & $20.;
cards;
* '''[[Nick]]'''
* [[KK Circle]]
* [[Spenser]]
||-
* Cool
||
Name
;
data want;
set have;
want=compress(x,' ','ka');
if want>' ';
run;
Use compress and tell it which class of characters to keep.
data x;
input x $32.;
xnew = compress(x,,'KADS');
cards;
x
* '''[[Nick]]'''
* [[KK Circle]]
* [[Spenser]]
||-
* Cool
* Cool 9
||
Name
;;;;
run;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: