write into new line when pressed ENTER

Reply
Occasional Contributor
Posts: 11

write into new line when pressed ENTER

Hi all,

Assume, I have a macro, where we have only one argument text= .Let's call that macro test.

This macro should put entered text into .txt.

The question is, Is it possible to put entered text into few lines, just like you would enter into SAS editor.

For example:

%test(text=This is just a test. [Pressed ENTER]

                 This is a new line. [Pressed ENTER]

                 Another line.

        );

And I would like to see this text with same structure in .txt as:

This is just a test.

This is a new line.

Another line.

There is a macro in proceedings, but it uses a special symbol for ENTER (like comma or |).

What I need is pure text with no addings.

Thank you

Super User
Super User
Posts: 7,720

Re: write into new line when pressed ENTER

No, as per the proceedings, a carriage return is a non visable special character.  This is the only way to get returns in text.  If you can only use pure text, i.e. number/chars then it will all be one line of text.

As for getting this out to a file then:

filename textfile "c:\test.txt";

data _null_;

     file textfile;

     put "Hello World";

     put "Goodbye World";

run;

Will have in the text file the two strings on separate lines - they still have the carriage return!

Super User
Super User
Posts: 6,845

Re: write into new line when pressed ENTER

No. 

The macro call that you posted would be consider part of the program stream to SAS. This will be parsed just like any other code.  SAS does not consider the end of line as different than any other white space when parsing a program.

Valued Guide
Posts: 3,208

Re: write into new line when pressed ENTER

This is the first question I see somebody is wanting to put a newline character into a string. the byte code is: '0a'x

this will cause a lot of issues as you wanted to do something with it we do not understand. The macro-quoting is field full of mines.

Just wanting a nice lay-out than go for ODS.

---->-- ja karman --<-----
Super User
Posts: 11,134

Re: write into new line when pressed ENTER

Are you attempting to do something with multiple undefined lines or will it always be a fixed number of lines? If the later, there MAY be a solution if you describe how you intend to use the macro. Otherwise we're flying kind of blind.

Valued Guide
Posts: 2,177

Re: write into new line when pressed ENTER

Hi Karolisb

When your %test runs where should its output appear?

peterC

Occasional Contributor
Posts: 11

Re: write into new line when pressed ENTER

Well basically it could appear anywhere, in a table's cell, .txt, html, etc.

Valued Guide
Posts: 2,177

Re: write into new line when pressed ENTER

since it will processed (for output) in later stages, I would suggest you insert the handling instructions appropriate to that stage. Since the stage looks like PUT statement to text, your macro value could look like

'Text1' '0a'x 'Text2' '0a'x 'Text3'

When Text1-3 are in variables named txt1-3, a suitable way of storing the 'target' value in a macro variable could be

  CALL SYMPUTX( 'mVar', catx( " '0a'x ", txt1, txt2, txt3 ) ) ;

hope this works for you

Respected Advisor
Posts: 3,788

Re: write into new line when pressed ENTER

Maybe this would be adequate.

%macro test(file=log);
   data _null_;
      infile cards;
      file &file;
      input;
      put _infile_;
  
%mend;

%
test()
cards;
This is just a test.
This is a new
line.
Another
line.
;;;;
       
Ask a Question
Discussion stats
  • 8 replies
  • 393 views
  • 6 likes
  • 7 in conversation