Help using Base SAS procedures

Creating list of emails with a semi colon at the end of each in a text file.

Accepted Solution Solved
Reply
Super Contributor
Posts: 398
Accepted Solution

Creating list of emails with a semi colon at the end of each in a text file.

I have a data table that has a list of emails

Bob@test.com

Jim@test.com

Steve@test.com

Cindy@test.com

Kelly@test.com

I want to create a text file that has these in a continous list like this

Bob@test.com;Jim@test.com;Steve@test.com;Cindy@test.com;Kelly@test.com;

proc sql noprint ;

select email into :emails separated by ' ; '

from eData

;

quit;

But whenever I put I get errors and I think it has to do with the semi-colon at the end.

Thank you


Accepted Solutions
Solution
‎10-11-2011 05:54 PM
Super User
Super User
Posts: 6,499

Re: Creating list of emails with a semi colon at the end of each in a text file.

You are pulling the values into a macro variable.  How did you try to get them into a text file?

It is probably much easier to just write them directly into the text file.

data have;

  input email $50. ;

cards;

Bob@test.com

Jim@test.com

Steve@test.com

Cindy@test.com

Kelly@test.com

run;

data _null_;

  file "email_list.txt" lrecl=20000 dlm=';' ;

  if eof then put;

  set have end=eof;

  put email @@ ;

run;

data _null_;

  infile "email_list.txt" lrecl=20000;

  input;

  list;

run;

RULE:     ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9--

1         Bob@test.com;Jim@test.com;Steve@test.com;Cindy@test.com;Kelly@test.com 70

NOTE: 1 record was read from the infile "email_list.txt".

      The minimum record length was 70.

      The maximum record length was 70.


View solution in original post


All Replies
Solution
‎10-11-2011 05:54 PM
Super User
Super User
Posts: 6,499

Re: Creating list of emails with a semi colon at the end of each in a text file.

You are pulling the values into a macro variable.  How did you try to get them into a text file?

It is probably much easier to just write them directly into the text file.

data have;

  input email $50. ;

cards;

Bob@test.com

Jim@test.com

Steve@test.com

Cindy@test.com

Kelly@test.com

run;

data _null_;

  file "email_list.txt" lrecl=20000 dlm=';' ;

  if eof then put;

  set have end=eof;

  put email @@ ;

run;

data _null_;

  infile "email_list.txt" lrecl=20000;

  input;

  list;

run;

RULE:     ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9--

1         Bob@test.com;Jim@test.com;Steve@test.com;Cindy@test.com;Kelly@test.com 70

NOTE: 1 record was read from the infile "email_list.txt".

      The minimum record length was 70.

      The maximum record length was 70.


Super User
Super User
Posts: 6,499

Re: Creating list of emails with a semi colon at the end of each in a text file.

It seems to be impossible to prevent the editor from converting text that LOOK like email addresses into hyperlinks.

:smileycry:

Respected Advisor
Posts: 3,777

Re: Creating list of emails with a semi colon at the end of each in a text file.

Tom wrote:

It seems to be impossible to prevent the editor from converting text that LOOK like email addresses into hyperlinks.

:smileycry:

This is a test to see if syntax box prevents hyperlink.

data have;

  input email $50. ;

cards;

Bob@test.com

Jim@test.com

Steve@test.com

Cindy@test.com

Kelly@test.com

run;

data _null_;

  file "email_list.txt" lrecl=20000 dlm=';' ;

  if eof then put;

  set have end=eof;

  put email @@ ;

run;

data _null_;

  infile "email_list.txt" lrecl=20000;

  input;

  list;

run;

Super User
Super User
Posts: 6,499

Re: Creating list of emails with a semi colon at the end of each in a text file.

What is a syntax box? How did you create it?

Respected Advisor
Posts: 3,777

Re: Creating list of emails with a semi colon at the end of each in a text file.

  1. click "use advanced editor"
  2. click the "double arrow" next to smile :smileyplain:.
  3. click "syntax highlighting"
  4. click "plain"

I use plain.  Why SAS is not an option is beyond my comprehension. :smileyconfused:

Super User
Posts: 9,676

Re: Creating list of emails with a semi colon at the end of each in a text file.

Click upper right button HTML.

And add these thing into it.

E-mail of hyperlink will not appear any more

<pre>

proc print ..

</pre>

Ksharp

Super User
Super User
Posts: 6,499

Re: Creating list of emails with a semi colon at the end of each in a text file.

Thanks.  I have played with the HTML, but I am frustrated that it puts in so many redundant <font> and <span> tags.  Perhaps if I start with the HTML editor I could prevent that.

Super User
Posts: 9,676

Re: Creating list of emails with a semi colon at the end of each in a text file.

Since You want it in a txt file ,why use Macro variable to get it. Data step can solve it easily.

data have;
  input email $50. ;
cards;
Bob@test.com
Jim@test.com
Steve@test.com
Cindy@test.com
Kelly@test.com
;
run;
data _null_;
  file "c:\email_list.txt" lrecl=20000  ;
  set have end=eof;
  put email +(-1) ';' @@ ;
run;

Ksharp

Super Contributor
Posts: 398

Creating list of emails with a semi colon at the end of each in a text file.

Thank you to both of you for your suggestions.  The data step with the put and the @@ was the way to go.

Thanks again

Valued Guide
Posts: 2,175

Re: Creating list of emails with a semi colon at the end of each in a text file.

why was it a problem for the macro language?

It is what macro quoting is about (well one of)

%let list =

Bob@test.com

Jim@test.com

Steve@test.com

Cindy@test.com

Kelly@test.com

;

%let delimited = %qsysfunc( translate( %sysfunc( compbl( &list)), %str(Smiley Wink, %str( ) ));

%put &delimited ;

Here is the log output

164 %put &delimited ;

Bob@test.com;Jim@test.com;Steve@test.com;Cindy@test.com;Kelly@test.com

those mail envelope icons are presented by this forum viewer and are not present on the assgnment of %let,  nor output from SAS  Message was edited by: Peter Crawford (just after posting original)

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 10 replies
  • 221 views
  • 3 likes
  • 5 in conversation