BookmarkSubscribeRSS Feed
D_Z_
Obsidian | Level 7

The code is below.  When the data gets concatenated the way it works right now is that it puts a space in between each line its concentrating.  what i would like it to do is put a carriage return instead.  Can anyone help me with this modification.  I have not found anything (prob because i couldn't determine the right search words) that will do this for me.

 

data  work.order_notes;
length order_notes $ 10000 /* need to be the max */;
     set sorted;
     by odr_odr_number dt_crtd;
     retain order_notes;
     if first.odr_odr_number then order_notes = scratch_pad;
     else order_notes=trim(order_notes) || ' ' || trim(scratch_pad);
     DROP SCRATCH_PAD;
     if last.odr_odr_number then output;
run;

thanks to anyone that can help me with this one.

 

Dean

5 REPLIES 5
DWilson
Pyrite | Level 9

@D_Z_ wrote:

The code is below.  When the data gets concatenated the way it works right now is that it puts a space in between each line its concentrating.  what i would like it to do is put a carriage return instead.  Can anyone help me with this modification.  I have not found anything (prob because i couldn't determine the right search words) that will do this for me.

 

data  work.order_notes;
length order_notes $ 10000 /* need to be the max */;
     set sorted;
     by odr_odr_number dt_crtd;
     retain order_notes;
     if first.odr_odr_number then order_notes = scratch_pad;
     else order_notes=trim(order_notes) || ' ' || trim(scratch_pad);
     DROP SCRATCH_PAD;
     if last.odr_odr_number then output;
run;

thanks to anyone that can help me with this one.

 

Dean


Well, on windows:

 

0x0D is hexadecimal for carriage return

0x0A is hex for line feed

0x0D0A is hex for carriage return followed by line feed

 

You can used one of these hex values as the separator instead of a space but you are creating a character variable in a SAS data set so I'm not sure how this helps you.

 

order_notes=trim(order_notes) || '0x0D0A' || trim(scratch_pad);

 

 

Hrm, you might need to tell SAS that 0x0D0A is hex, maybe like this:

order_notes=trim(order_notes) || '0x0D0A'x || trim(scratch_pad);

 

jhammouda
Obsidian | Level 7

Hi D_Z,

replace ' ' in the concatenation with the hex code for CR  '0D'x

 

ErikLund_Jensen
Rhodochrosite | Level 12

Hi @D_Z_ 

 

As @DWilson suggests, use a hex constant in the concatenation. But use only '0D0A'x for a Windows line break, or '0A'x for a Linux line break. Don't use '0x0D0A or '0x0A' because '0x' is not a hex character code and causes an error in SAS. Valid hex codes are 00-FF.

 

But I wonder why you would want those line breaks. Normally one would do a lot to get rid of them, because they have no meaning inside SAS and isnt' shown in a SAS table view. They may cause a lot of trouble when they come out of SAS. They will generate line breaks If data is written to (say) a CSV file, so the file is corrupt afterwards with broken records. They don't do any harm in export to Excel, but they don't work either, they just disappear.

kovamk
Calcite | Level 5

Hi Erik, so are you saying when using sas to export data into excel, you can't use a carriage return to have the data come out in 2 rows in excel?  i.e. I'm trying to get this wording split into 2 lines in excel:

LABEL HEDIS_COLON_GAP = 'Colorectal Cancer Screening (Display for MA)' ;

 

I'd like the final result to have 'Colorectal Cancer Screening' on the first line in the cell and (Display for MA) on the second line in the cell. 

 

Colorectal Cancer Screening

(Display for MA)

 

But I can't get it to work using any of the code that has been suggested online. I either get an error or the code doesn't work.

 

Thanks,
Mike

ErikLund_Jensen
Rhodochrosite | Level 12

Hi @kovamk 

 

Yes. At least I never got it to work. I remember a Stackowerflow post that addressed the problem, and it said something about the code actually being there, but not working until F2 is pressed in every cell, so to me that equals "not working".

 

I found a paper with a receipe to use ODS / proc print with a tagset to cheate the excel table. I haven´t tried it, but it is worth exploring:

https://www.pharmasug.org/proceedings/2014/CC/PharmaSUG-2014-CC07.pdf

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 5 replies
  • 1471 views
  • 2 likes
  • 5 in conversation