DATA Step, Macro, Functions and more

SAS QUERY

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 145
Accepted Solution

SAS QUERY

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


Accepted Solutions
Solution
‎03-01-2017 01:02 PM
Super User
Posts: 5,084

Re: SAS QUERY

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

 

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

 

 

View solution in original post


All Replies
Super User
Super User
Posts: 7,404

Re: SAS QUERY

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.

Frequent Contributor
Posts: 145

Re: SAS QUERY

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

Super User
Posts: 17,840

Re: SAS QUERY

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

Solution
‎03-01-2017 01:02 PM
Super User
Posts: 5,084

Re: SAS QUERY

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

 

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

 

 

Super Contributor
Posts: 408

Re: SAS QUERY

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

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 156 views
  • 1 like
  • 5 in conversation