BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Aexor
Lapis Lazuli | Level 10

Dear member,

 

Could you please help me in below query:

input

Data  one;

input all $50. ;

datalines; 

ram is "amazing"

shyan needs "/books/lamps"

we are "/travellling/"

;

run;

 

 I need output dataset New having values like this  in a new variable two.

 

two

amazing

/books/lamps

  /travellling/

 

   

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Hmm No wonder not participating here enough makes me lose touch consequential in not thinking of the following in the 1st place. Jeez!--

 


Data  one;

input all $50. ;

datalines; 
ram is "amazing"
shyan needs "/books/lamps"
we are "/travellling/"
;

run;


data two;
  set one;
  length want $50;
  want=scan(all,-2,'"');
run;

proc print noobs;run;
all want
ram is "amazing" amazing
shyan needs "/books/lamps" /books/lamps
we are "/travellling/" /travellling/

View solution in original post

4 REPLIES 4
novinosrin
Tourmaline | Level 20

Data  one;

input all $50. ;

datalines; 
ram is "amazing"
shyan needs "/books/lamps"
we are "/travellling/"
;

run;

data two;
  set one;
  length want $50;
  _k=findc(all,'"','b');
  _k1=findc(all,'"')+1;
  want=substr(all,_k1, _k-_k1);
  drop _k:;
run;

proc print noobs;run;
all want
ram is "amazing" amazing
shyan needs "/books/lamps" /books/lamps
we are "/travellling/" /travellling/
novinosrin
Tourmaline | Level 20

Hmm No wonder not participating here enough makes me lose touch consequential in not thinking of the following in the 1st place. Jeez!--

 


Data  one;

input all $50. ;

datalines; 
ram is "amazing"
shyan needs "/books/lamps"
we are "/travellling/"
;

run;


data two;
  set one;
  length want $50;
  want=scan(all,-2,'"');
run;

proc print noobs;run;
all want
ram is "amazing" amazing
shyan needs "/books/lamps" /books/lamps
we are "/travellling/" /travellling/
ballardw
Super User

@novinosrin wrote:

Hmm No wonder not participating here enough makes me lose touch consequential in not thinking of the following in the 1st place. Jeez!--

 


Data  one;

input all $50. ;

datalines; 
ram is "amazing"
shyan needs "/books/lamps"
we are "/travellling/"
;

run;


data two;
  set one;
  length want $50;
  want=scan(all,-2,'"');
run;

proc print noobs;run;
all want
ram is "amazing" amazing
shyan needs "/books/lamps" /books/lamps
we are "/travellling/" /travellling/

Maybe we need a self-assigned badge of the "Forehead pop" for such.

ChrisNZ
Tourmaline | Level 20

Like this?

WANT=scan(ALL, 2, '"');

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

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
  • 4 replies
  • 803 views
  • 5 likes
  • 4 in conversation