## SAS QUERY

Solved
Frequent Contributor
Posts: 147

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

Rakesh

Accepted Solutions
Solution
‎03-01-2017 01:02 PM
Super User
Posts: 6,648

## Re: SAS QUERY

Posted in reply to rakeshvvv

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

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

All Replies
Super User
Posts: 9,465

## Re: SAS QUERY

Posted in reply to rakeshvvv

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: 147

## 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: 23,364

## Re: SAS QUERY

Posted in reply to rakeshvvv

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

Solution
‎03-01-2017 01:02 PM
Super User
Posts: 6,648

## Re: SAS QUERY

Posted in reply to rakeshvvv

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

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

Valued Guide
Posts: 531

## Re: SAS QUERY

Posted in reply to rakeshvvv

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