VAPODACA
VAPODACA

Reputation: 1

Pull string between phrase and period

I was given an excel file where someone stored all of the information in a single column (var1). I need to pull information but it will be in random orders. Good thing is the person gave the information and then put a period after it. I pulled the var1 in SAS.

3 Examples of Var1 oberservations:

  1. Type = 2. Size = 4 in x 12 in. Group = ABC grouping.

  2. Group = A and B Holdings. Type = 1.

  3. Group = Mark H and Company.

The variable I need to pull is group. It always starts with "Group = " and has a period in the end. But will be anywhere within the var1 (so you can't name a specific period. Sometimes it may not exist. This variable can be any length in words. I just need to pull the string between "Group = " and the period.

This can't be done in excel due to the size of the dataset.

I have tried scan, find, splitting at the period, and I am not sure what to do at this point to organize it.

Upvotes: 0

Views: 29

Answers (1)

data _null_
data _null_

Reputation: 9109

How about this?

data have;
   infile cards4 truncover;
   input line $100.;
   list;
   cards4;
Type = 2. Size = 4 in x 12 in. Group = ABC grouping.
Group = A and B Holdings. Type = 1. 
Group = Mark H and Company. 
;;;;
run;


data more;
   set have;
   infile cards4;
   input @1 @;
   _INFILE_ = line;
   length type size group $48;
   _infile_= transtrn(_infile_,' = ','=');
   input (_all_)(=);
   list;
   cards4;
Type = 2. Size = 4 in x 12 in. Group = ABC grouping.
Group = A and B Holdings. Type = 1. 
Group = Mark H and Company. 
;;;;
run;
proc print;
run;

Upvotes: 1

Related Questions