- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I have the below dataset:
Name
Jack Chirikjian
Dean Rosenthal
Dean Rosenthal
Dean Rosenthal
John Adams
John Adams
I need a code which will conditionally create text (tab delimited files), each containing the names.
E.g: File1.txt
Jack Chirikjian
File2.txt
Dean Rosenthal
Dean Rosenthal
Dean Rosenthal
File3.txt
John Adams
John Adams
Also, I need to email these files as attachments to their respective emails. Eg Jack will get an email with file1.txt, Dean will get with File2.txt and so on. (assume I have the emails addresses)
Greatly appreciate the inputs.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
consider that you have the email address as well in the dataset. Then this code should be helpful
data have;
input Name &$30. email :$20.;
cards;
Jack Chirikjian jag@gmail.com
Dean Rosenthal de@gmail.com
Dean Rosenthal de@gmail.com
Dean Rosenthal de@gmail.com
John Adams jo@gmail.com
John Adams jo@gmail.com
;
proc sql;
select distinct name, email into : name1-:name&sysmaxlong, :email1-:email&sysmaxlong from have;
quit;
%put &name1 &name2 &email2;
%macro email;
%do i = 1 to 3;
DATA _NULL_;
set have;
where name="&&name&i";
FILE '~\&&file&i.txt';
PUT name;
RUN;
FILENAME MailBox EMAIL "&&email&i"
SUBJECT='Mail message with txt attachment'
attach="~\&&file&i.txt";
data _null_;
file mailbox;
put 'hi';
run;
%end;
%mend;
%email;
Thanks,
Jag
Jag
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data _null_;
file "filex.txt" filevar=filnam; * filex.txt is just a placeholder;
set have;
by name;
retain counter 0;
if first.name
then do;
counter + 1;
filnam = 'file' !! trim(put(counter,3.)) !! '.txt';
end;
put name;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
consider that you have the email address as well in the dataset. Then this code should be helpful
data have;
input Name &$30. email :$20.;
cards;
Jack Chirikjian jag@gmail.com
Dean Rosenthal de@gmail.com
Dean Rosenthal de@gmail.com
Dean Rosenthal de@gmail.com
John Adams jo@gmail.com
John Adams jo@gmail.com
;
proc sql;
select distinct name, email into : name1-:name&sysmaxlong, :email1-:email&sysmaxlong from have;
quit;
%put &name1 &name2 &email2;
%macro email;
%do i = 1 to 3;
DATA _NULL_;
set have;
where name="&&name&i";
FILE '~\&&file&i.txt';
PUT name;
RUN;
FILENAME MailBox EMAIL "&&email&i"
SUBJECT='Mail message with txt attachment'
attach="~\&&file&i.txt";
data _null_;
file mailbox;
put 'hi';
run;
%end;
%mend;
%email;
Thanks,
Jag
Jag
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Little correction on Jag's code.
It should be
%do i = 1 %to 3; *percentage symbol was missing in initial code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the correction, Ram
Jag
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks a lot Jagadish! Works for me!