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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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