BookmarkSubscribeRSS Feed
ammarhm
Lapis Lazuli | Level 10

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

 

1 REPLY 1
Oligolas
Barite | Level 11

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 -

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 571 views
  • 0 likes
  • 2 in conversation