DATA Step, Macro, Functions and more

How do I export a dataset using Greek font?

Reply
Occasional Contributor
Posts: 17

How do I export a dataset using Greek font?

[ Edited ]

Hi all,

 

I have a dataset in SAS (9.4) with a variable that reads with weird characters such as ÁÂÄÇÑÁ, the source language is Greek. When I change the font to "Greek" (right click on column, column attributes, fonts, data font, Script=Greek)  SAS reads the column in Greek language, which is great. However, the cell the values of the variable still contain weird names ÁÂÄÇÑÁ (I see this simply by clicking on a cell). As a result,  when I export the dataset in a txt file, the values still appear with the weird font. Is there a way to export the file in txt or csv or anything else that will use the Greek letters? No other source online can read these characters (ÁÂÄÇÑÁ) other than SAS, so since SAS can read Greek, there has to be a way to export it in Greek, right? 

 

I would really appreciate your help or any advice. Many thanks in advance. 

 

 

Super User
Super User
Posts: 7,039

Re: How do I export a dataset using Greek font?

What ENCODING are you using in your SAS session? To reliably use multiple languages you should be running using UTF-8 encoding.  That can handle Greek and other non 7bit ASCII character codes.  Note you still might need to use encoding to read your original file correctly if it is using single byte encoding with a codepage that supports interpretting some characters as meaning Greek glyphs.

 

If you write the text files using UTF-8 encoding then most other programs will recognize the characters without having the change the "font".

Occasional Contributor
Posts: 17

Re: How do I export a dataset using Greek font?

Thanks a lot for your response Tom. This is helpful, but doesn't solve my issue yet. 

 

Using utf-8 encoding doesn't work and gives me this error:  The file 'path\temp.txt' could not be opened. A byte-order mark indicates that the data is encoded in "utf-16le". This conflicts with the "utf-8" encoding that was specified for the fileref


Using utf-16 allows me to import the file, but it still does not change the format from weird symbols (ÁÃÉÏÓ ÌÕÑÙÍ) to Greek. You mentioned that I still need to use encoding to read the original file correctly it if is using single byte encoding. How do I do that? I have a simple file (see attached) and use the code below to import in the appropriate text. 


filename extfile 'path\temp.txt' encoding="utf-16" ;
data want;
infile extfile ;
input varname $30. ;
run;

Thanks so much again. 

Super User
Super User
Posts: 7,039

Re: How do I export a dataset using Greek font?

Your SESSION needs to be running using UTF-8 encoding, you have to set that when SAS starts.
Then you should be about to read the actual file using the encoding for that particular file and SAS will be able to transcode the characters into valid UTF-8 characters.
Occasional Contributor
Posts: 17

Re: How do I export a dataset using Greek font?

[ Edited ]

Thanks again Tom. I'm afraid even when I change the whole session (by chancing the sasv9.sfg file) it changes the encoding but it doesn't recognize Greek. That was the most confusing part. I tried every possible encoding online and none works for these characters. But when I change the font script in SAS then the text is correct. The problem is I can't replace the values in the column using the font script SAS is "superficially" using to display the Greek text. Many thanks again for checking with me.

Ask a Question
Discussion stats
  • 4 replies
  • 86 views
  • 1 like
  • 2 in conversation