It is well known that RTF code ‘\line’ can be used to create a new line in ODS RTF or ODS TAGSETS.RTF destination. But few people know how to create a new line in excel file or sas programing file or xml file. This post will post a solution that I found recently – to covert HEX value of  CR/LF/CRLF to character.

CR, LF and CRLF

CR (Carriage Return, \r, 0x0D in hexadecimal, 13 in decimal) moves the cursor to the beginning of the line without advancing to the next line.

LF (Line Feed, \n, 0x0A in hexadecimal, 10 in decimal) moves the cursor down to the next line without returning to the beginning of the line.

CRLF (Carriage Return Line Feed, \r\n, 0x0D0A) moves the cursor down to the next line and then to the beginning of the line.

How to create line break in excel file using ODS Excel?

Input function can be used to convert hex value into character.

data a;
  test = "20MAR2020 (1)/"||input('0D',$hex2.)||"28MAR2020 (9)"; output;
  test = "20MAR2020 (1)/"||input('0A',$hex2.)||"28MAR2020 (9)"; output;
  test = "20MAR2020 (1)/"||input('0D0A',$hex2.)||"28MAR2020 (9)"; output;
run;

ods excel file="E:/test.xlsx";
ods excel options(autofilter="yes" sheet_name= "test"
                  sheet_interval="PROC" embed_footnotes_once = "off"
                  embed_titles_once = "off" column_repeat = "header"
                  flow="TABLES");

    proc report data = a;
    run;

ods excel close;
ods listing;

How to create line break in excel file using ODS Listing?

data a;
  test = "20MAR2020 (1)/"||input('0D',$hex2.)||"28MAR2020 (9)"; output;
  test = "20MAR2020 (1)/"||input('0A',$hex2.)||"28MAR2020 (9)"; output;
  test = "20MAR2020 (1)/"||input('0D0A',$hex2.)||"28MAR2020 (9)"; output;
run;

ods listing file="E:/test.lst";

    proc report data = a;
      column test;
      define test/ " " style(column)=[just=left];
    run;

ods listing;

How to create line break in PUT statement?