BookmarkSubscribeRSS Feed
ColleenCB
Fluorite | Level 6

Hi All,

I have a DATA table that needs exporting to Excel but it seems to have Return characters etc within it and distorts the export.

 

This is the "univeral" script that we use in SQL & need to find something similar to run in BASE SAS 9.4 to remove the characters from the data before exporting it.

 

SELECT QUESTION_TEXT

,REPLACE(REPLACE(QUESTION_TEXT,CHAR(10),''),CHAR(13),'')

FROM BI_Staging.dbo.XXFRGSAM_QUESTION_LIBRARY

WHERE (QUESTION_TEXT LIKE '%'+CHAR(10)+'%')

OR (QUESTION_TEXT LIKE '%'+CHAR(13)+'%')

 

Can someone help please.

2 REPLIES 2
Tom
Super User Tom
Super User

If you want to remove CR and LF from strings in SAS then use the COMPRESS() function.

 

data want ;
  set have;
  QUESTION_TEXT = compress(QUESTION_TEXT,'0D0A'x);
run;

If you want to replace them with single characters you can use the TRANSLATE() function. For example to replace them with spaces you could use.

data want ;
  set have;
  QUESTION_TEXT = translate(QUESTION_TEXT,'  ','0D0A'x);
run;
ColleenCB
Fluorite | Level 6

The 2 lines should be one but the problem is that there is a carriage return in the original data is a problem and should be removed.

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
  • 2 replies
  • 2468 views
  • 0 likes
  • 2 in conversation