BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jerry898969
Pyrite | Level 9

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

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

10 REPLIES 10
Tom
Super User Tom
Super User

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.


Tom
Super User Tom
Super User

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

:smileycry:

data_null__
Jade | Level 19

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;

Tom
Super User Tom
Super User

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

data_null__
Jade | Level 19
  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:

Ksharp
Super User

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

Tom
Super User Tom
Super User

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.

Ksharp
Super User

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

jerry898969
Pyrite | Level 9

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

Thanks again

Peter_C
Rhodochrosite | Level 12

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(;), %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)

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!

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
  • 10 replies
  • 1340 views
  • 3 likes
  • 5 in conversation