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

Dear All,

 

Can some one guide me with the below query.

 

Part 1/Cycle 1/Day 1/Pre-Dose: I have to output only: Cycle 1/Day 1 from adjacent string(Have to strip off values before the first slash and after the last).

 

Part 1/Cycle 1/Day 1/6 Hr: Cycle 1/Day 1

Part 1/Cycle 1/Day 15/Pre-Dose: Cycle 1/Day 15

Part 1/Cycle 1/Day 8: Cycle 1/Day 8

Part 1/Cycle 1/Day 21: Cycle 1/Day 21

Also, Can someone please guide in converting 10FEB2015 into SAS DATE.

Thanks in advance.

Rakesh

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

To pull out the middle pieces, here is an approach:

 

var = cats(scan(var, 2, '/'), '/', scan(var, 3, '/'));

 

 

View solution in original post

5 REPLIES 5
RW9
Diamond | Level 26 RW9
Diamond | Level 26

I am afraid not.  You have not provided any information - e.g. test data in the form of a datastep, or what you want the output to look like.  This code shows how you could trim off the first and fourth part - assuming your data is all four long:

data want;
  a="Part 1/Cycle 1/Day 1/Pre-Dose";
  b=strip(tranwrd(tranwrd(a,scan(a,4,"/"),""),scan(a,1,"/"),""));
run;

And this "10FEB2015" can be converted by using input("10FEB2015",date9.), or just "10FEB2015"d;

 

However further than that I can't say.

rakeshvvv
Quartz | Level 8

Hi,

 

Please find the below sample data. the data highlighted in blue is the sample data and output i would need is highlighted in PINK.

 

Part 1/Cycle 1/Day 1/6Hr: Cycle 1/Day 1

Part 1/Cycle 1/Day 15/Pre-Dose: Cycle 1/Day 15

Part 1/Cycle 1/Day 8: Cycle 1/Day 8

Part 1/Cycle 1/Day 21: Cycle 1/Day 21

Reeza
Super User

If the data is as described, the SCAN function is sufficient.

Astounding
PROC Star

To pull out the middle pieces, here is an approach:

 

var = cats(scan(var, 2, '/'), '/', scan(var, 3, '/'));

 

 

jklaverstijn
Rhodochrosite | Level 12

As your number of slashes is not always the same I would take the rule literally and look for first and last slash:

 

data test;
	length string $100;
	infile cards dlm='#';
	input string $;
	firstslash=findc(string, '/');
	lastslash=findc(string, '/', '', -100);
	want=substr(string, firstslash+1, lastslash-firstslash-2);
	cards;
Part 1/Cycle 1/Day 1/6Hr
Part 1/Cycle 1/Day 15/Pre-Dose
Part 1/Cycle 1/Day 8
Part 1/Cycle 1/Day 21
;

Hope this helps,

- Jan

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 5 replies
  • 1705 views
  • 1 like
  • 5 in conversation