I am having some troubles reading in data files when using SAS University Edition.
I am teaching myself SAS using books like The Little SAS Book and its companion of Exercises and Projects (as well as using a bunch of other books).
I am having a consistent problem with printing libraries that have non English Characters e.g. ó, ú, ç or ä etc.
These characters appear in a data file that I am reading in. The initial input works fine without any errors but when I try to print out the data I get the following error:
I have looked at other similar postings such as the one [here] but can't seem to resolve the issue. It really seems the problem comes from the non-English character being present in the .txt file.
Now for some details:
I am Using:
SAS University Edition
Windows 10 version 1703
Firefox 52.0.2 (32-bit)
My code:
DATA Big_Companies; INFILE '/folders/myfolders/TheLittleSASBook/CodePractice/Chapter02/LogData/BigCompanies.txt'; INPUT Ranking 1-5 Company_Name $ 6-34 Country $ 35-52 Sales $ 53-59 Profits $ 60-68 Assets $ 69-78 Market_Value $ 79-88 ; RUN; PROC PRINT DATA = big_companies; RUN;
The Data file is attached:
The Log file is attached:
Many thanks in advance, I appreciate the help
- Pete
Just a guess, but try to add
encoding=wlatin1
in the infile statement. It might be that you get trouble because of the UTF-8 encoding of SAS UE.
Just a guess, but try to add
encoding=wlatin1
in the infile statement. It might be that you get trouble because of the UTF-8 encoding of SAS UE.
Sorry I didn't post my thanks note earlier,
Yes, it was definately the encoding, I added in this line of text and it worked perfectly.
I appreciate the help from you and all the others who chimed in.
Pete
That does seem strange.
Is it possible that SAS is using wrong encoding when reading the file?
When trying to view your attached files on this site I see that the non-ascii characters make the columns not line up. Is it possible that by using column input you have truncated a multi-byte unicode character and hence made it invalid?
Did you try reading the file using modified list mode input instead?
DATA Big_Companies;
INFILE '/folders/myfolders/TheLittleSASBook/CodePractice/Chapter02/LogData/BigCompanies.txt';
length Ranking 8 Company_Name $40 Country $20 Sales Profits Assets Market_Value $12 ;
input ranking company_name & Country & sales -- market_value;
run;
I think it is definitely the encoding.
Change another ODS destination ?
DATA Big_Companies;
INFILE '/folders/myfolders/BigCompanies.txt';
INPUT Ranking 1-5
Company_Name $ 6-34
Country $ 35-52
Sales $ 53-59
Profits $ 60-68
Assets $ 69-78
Market_Value $ 79-88
;
RUN;
ods _ALL_ CLOSE;
ods html file='/folders/myfolders/x.htm';
PROC PRINT DATA = big_companies;
RUN;
Open x.htm by hand .
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.