Carriage Return in a Quote?

Accepted Solution Solved
Reply
Contributor
Posts: 31
Accepted Solution

Carriage Return in a Quote?

Hey all, I have the following:

 

(case when t1.Line_Number=1 then 
            "The big brown dog jumped over the red fence. Then went to bed" 
            end) AS Special_Instructions;

Is there a special character in SAS to insert a carriage return after the period by the word "fence" ? I would like to be able to export these and similar comments into Excel as labels, but some will need carriage returns. Not sure SAS has a code to enter within the quote that will export a carriage return, or even make a carriage return within the SAS text variable.  thanks!

 

 

 

 

 

 


Accepted Solutions
Solution
4 weeks ago
Super User
Super User
Posts: 6,502

Re: Carriage Return in a Quote?

You can insert any hexcode you want. The hexcode for CR is '0D'x.

(case when t1.Line_Number=1 then 
            'The big brown dog jumped over the red fence.'||'0D'x||'Then went to bed'
            end) AS Special_Instructions;

I also changed the qutoes to single quotes so that you could also insert characters like & and % that would be macro triggers if enclodes in double quotes.

View solution in original post


All Replies
Contributor
Posts: 62

Re: Carriage Return in a Quote?

Have you tried a '\r' or used the ASCII equivalent ('13'x)?

 

 

Contributor
Posts: 31

Re: Carriage Return in a Quote?

@AlanC

 

I am not sure where to place those within my quote. I have tried \r, '\r' to no avail and am unsure how to enter the ascii.  Any ideas?

Contributor
Posts: 62

Re: Carriage Return in a Quote?

I foudn this in another thread. To get the valid hex, use this:

 

cr=input('0D',$hex2.);

 

Note: 0D == '13' 

 

A valid SAS statement would be:

 

x = "Test the carriage return" || cr || right now" ;

 

See if that helps.

 

 

Solution
4 weeks ago
Super User
Super User
Posts: 6,502

Re: Carriage Return in a Quote?

You can insert any hexcode you want. The hexcode for CR is '0D'x.

(case when t1.Line_Number=1 then 
            'The big brown dog jumped over the red fence.'||'0D'x||'Then went to bed'
            end) AS Special_Instructions;

I also changed the qutoes to single quotes so that you could also insert characters like & and % that would be macro triggers if enclodes in double quotes.

Super User
Super User
Posts: 7,413

Re: Carriage Return in a Quote?

If you want nice readbale output in excel then using a reporting procedure is the way to go:

ods excel file="c:\xyz.xlsx";
proc report data=have nowd split="~";
  columns _all_;
  define var1 / label="Something here~which needs~Splitting";
...
run;
ods excel close;

Its rarely a good idea to put things in the data which have no purpose other than for reporting (it just makes processing the data harder).

Contributor
Posts: 31

Re: Carriage Return in a Quote?

Tom's response was partially correct. Excel does not honour the carriage return, Word does though. When I used "new line" Excel then honored it (Word as well):

 

case when t1.Line_Number=1 then 'The big brown dog jumped over the red fence.' ||'0A'x|| 'Then went to bed' end
☑ This topic is solved.

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

Discussion stats
  • 6 replies
  • 117 views
  • 0 likes
  • 4 in conversation