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

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.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

View solution in original post

3 REPLIES 3
ballardw
Super User

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.

novinosrin
Tourmaline | Level 20

data have;
input  x & $20.;
cards;
* '''[[Nick]]'''
* [[KK Circle]]
* [[Spenser]]
||-
* Cool
||
Name
;

data want;
set have;
want=compress(x,' ','ka');
if want>' ';
run;
data_null__
Jade | Level 19

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;

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

What is Bayesian Analysis?

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 438 views
  • 3 likes
  • 4 in conversation