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

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!

 

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

6 REPLIES 6
AlanC
Barite | Level 11

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

 

 

https://github.com/savian-net
BCNAV
Quartz | Level 8

@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?

AlanC
Barite | Level 11

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.

 

 

https://github.com/savian-net
Tom
Super User Tom
Super User

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.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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).

BCNAV
Quartz | Level 8

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 6 replies
  • 9941 views
  • 0 likes
  • 4 in conversation