DATA Step, Macro, Functions and more

Removing Special Characters when exporting to XLSX

Reply
New Contributor
Posts: 4

Removing Special Characters when exporting to XLSX

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.

Super User
Super User
Posts: 7,039

Re: Removing Special Characters when exporting to XLSX

Posted in reply to ColleenCB

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;
New Contributor
Posts: 4

Re: Removing Special Characters when exporting to XLSX

Posted in reply to ColleenCB

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.

Ask a Question
Discussion stats
  • 2 replies
  • 147 views
  • 0 likes
  • 2 in conversation