I'm trying to accomplish the following in SAS.
My dataset looks like this:
|ID |Description
|----|-----------------
| 1 |Object Car_bmw Processed.Colour changed from Red to Green Mileage changed from 30 to 32 Object Car_Audi Processed.Colour changed from Blue to White Mileage changed from 0 to 5
| 2 |Object Car_Kia Processed. Colour changed from White to Black Mileage changed from 3 to 9 Value changed from 12034 to 11029
| 3 |Object Phone_Iphone Processed. Colour changed from Black to Green Value changed from 300 to 290 Object Car_bmw Processed. Colour changed from White to Red Mileage changed from 100 to 50
I would like to create a new object column which will split the "description" column into so:
|ID |Index| Description
|----|-----|-----------
| 1 | 1 | Object Car_bmw Processed.Colour changed from Red to Green Mileage changed from 30 to 32
| 1 | 2 | Object Car_Audi Processed.Colour changed from Blue to White Mileage changed from 0 to 5
| 2 | 1 | Object Car_Kia Processed.Colour changed from White to Black Mileage changed from 3 to 9 Value changed from 12034 to 11029
| 3 | 1 | Object Phone_Iphone Processed.Colour changed from Black to Green Value changed from 300 to 290
| 3 | 2 | Object Car_bmw Processed. Colour changed from White to Red Mileage changed from 100 to 50
I tried using the following functions to separate the objects and "descriptions" into different rows. I used "Processed." as a delimiter since that is common between the different objects. However, it didn't work
data want;
set have;
do index = 1 to countw(LOG_LONG_DESC,'Processed.');
line_part = dequote(scan(LOG_LONG_DESC,index,'Processed.'));
OUTPUT;
end;
run;
Assuming there is some delimiter between the lines in original photograph then I would recommend splitting it into one observation per line and making a second variable that increments when the word PROCESSED appears in the line.
Let's make a sample dataset that is using CR as the delimiter between the lines.
Now we can use COUNTW() and SCAN() to split it into lines and FINDW() to detect when a line has PROCESSED in it.
Result