BookmarkSubscribeRSS Feed
pp2014
Fluorite | Level 6

I am trying to read the email_list file and output only email addresses separated by semi-column.  But my code goes into a loop.

Can anybody help me in this??

 

email_file.txt has following records:

 

Doe, John <john.doe@abc.com>;Smith, Jeff <jeff.smith@abc.com>; lever, dave <dave.lever@abc.com>

 

 

Below is my code:

data test;
length text $32767;

infile 'c\email_file.txt' lrecl=32767 dsd dlm='09'x truncover;

input text $;

run;

data t1;
set test;
length tx3 $500;
tx3="";
tx1=text;
do until (length(cats(tx1))=0);
space_position = INDEX(tx1, '<');
slash_position = INDEX(tx1, '>');
space_to_slash = slash_position - space_position;
tx2 = substr(tx1, space_position+1, space_to_slash-1);
tx3=cats(tx3,tx2,";");
tx4=substr(tx1,find(tx1,";")+1);
tx1=tx4;
end;
run;

5 REPLIES 5
Jagadishkatam
Amethyst | Level 16
data want;
i=1;
set have;
do until(scan(text,i,';') eq '');
new=scan(text,i,';');
i+1;
output;
end;
run;
Thanks,
Jag
Ksharp
Super User
filename x temp; data _null_; file x; input; put _infile_; cards4; Doe, John ;Smith, Jeff ; lever, dave ;;;; run; data want; infile x dlm='>'; input @'<' email : $100. @@; run;
Ksharp
Super User

filename x temp;
data _null_;
file x;
input;
put _infile_;
cards4;
Doe, John ;Smith, Jeff ; lever, dave 
;;;;
run;





data want;
 infile x  dlm='>' lrecl=32767;
 input @'<' email : $100. @@;
run;

Jagadishkatam
Amethyst | Level 16

if only the email id has to be retrieved then please try

 

data want;
i=1;
set have;
do until(scan(text,i,';') eq '');
new=compress(scan(scan(text,i,';'),2,'<'),'>');
i+1;
output;
end;
run;
Thanks,
Jag
Tom
Super User Tom
Super User

Looks like you want to take the parts inside of the <>.  This code will do that and also take values that only have the email address without the name and so do not have any <>s.

 

You can scan the original list using ';' as the delimiter and then within each sub-string look for the values between the <> using scan function again, this time using both < and > as the delimiters.

 

data want;
  set test ;
  length want $32767 ;
  do i=1 to countw(text,';');
     want = catx(';',want,scan(scan(text,i,';'),-1,'<>'));
  end;
run;

 

sas-innovate-2024.png

 

Secure your spot at the must-attend AI and analytics event of 2024: SAS Innovate 2024! Get ready for a jam-packed agenda featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events.

 

Register by March 1 to snag the Early Bird rate of just $695! Don't miss out on this exclusive offer. 

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 930 views
  • 1 like
  • 4 in conversation