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;

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

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