DATA Step, Macro, Functions and more

Extracting part of a string

Reply
Regular Contributor
Posts: 182

Extracting part of a string

Hi everyone

I need help with 2 issues

 

1. I have a file containing thousands of enteries that look like this:

 

PatientFirstName;PatientLastName;PatientDateOfBirth;PatientID;HomeDoctorSalutation;HomeDoctorFirstName;HomeDoctorLastName;ExamType;ExamDate;ExaminerSalutation;ExaminerFirstName;ExaminerLastName; Comment 3;Image Comment 4;_x000D_

"John";"Doe";"01/01/99";"9999999";"MS";"Alex";"Josef";"surgery";"01/01/17";"MR";"John";"Watson";"Mr";"Sherlock";"Holmes";"GX";"11111";"";"";"";"";"";"";

 

I need to extract the parts I marked in red, basically, the first 4 entries between citation marks, and the 9th one. They are always in that order and always between citations

 

Then Another file with entries as follows:

 

X:\1111111_5748392_222222222_DDDDD.PDF

 

I also need the entry I marked in red, basically the one between "\" and "_"

 

I know this is doable with regular expression, but it would probably take me a couples of days to figure out a solution, so reaching out to the community for some help please... 

 

Kind regards

 

AM

 

Regular Contributor
Posts: 164

Re: Extracting part of a string

[ Edited ]

Hi,

 

you can achieve what you want with this piece of code:

 

/*
I need to extract the parts I marked in red, basically, the first 4 entries between citation marks
and the 9th one. They are always in that order and always between citations
*/
proc import datafile="X:\YourFile.txt"
     out=test1
     dbms=csv
     replace;
     getnames=yes;
     delimiter=';';
;
run;

data test2;
   set test1;
   keep PatientFirstName PatientLastName PatientDateOfBirth PatientID ExamDate;
run;

/*
I also need the entry I marked in red, basically the one between "\" and "_"
*/
filename files pipe 'dir  "X:\*.pdf" /b/a-d ' lrecl=5000;
data a;
infile files truncover;
input files $char1000.;
files=scan(files,1,'_');
run;
________________________

- Cheers -

Ask a Question
Discussion stats
  • 1 reply
  • 85 views
  • 0 likes
  • 2 in conversation