While trying to contribute to https://communities.sas.com/t5/SAS-Programming/Encoding-from-LATIN1-to-UTF8-w-o-changing-files-time-... I proposed to make a combination of linux copy (cp) with -p option to preserve the original attributes, and create a view that will translate the encoding into the required one.
Later I used SAS-UE to test my proposed code and found that it doesn't work as expected. Code and log are:
73 data work.class (encoding='Latin1') / view=work.class; 74 set sashelp.class; 75 run; ERROR: The ENCODING= data set option is not supported for DATA step views. NOTE: View not saved due to errors. NOTE: The SAS System stopped processing this step because of errors.
It could be worthful to enable encoding, as translation tool, to views without need to copy the whole data thus saving disk space.
@Shmuel You might want to post this in the SASware Ballot Ideas forum.
@Shmuel You might want to post this in the SASware Ballot Ideas forum.
Thanks @ChrisNZ I'll do it soon.
I don't understand why that would be needed.
1 %put %sysfunc(getoption(encoding));
UTF-8
2 proc contents data=sashelp.class; run;
NOTE: PROCEDURE CONTENTS used (Total process time):
real time 0.39 seconds
cpu time 0.04 seconds
3 data class / view=class ;
4 set sashelp.class;
5 run;
NOTE: DATA STEP view saved on file WORK.CLASS.
NOTE: A stored DATA STEP view cannot run under a different operating system.
NOTE: DATA statement used (Total process time):
real time 0.13 seconds
cpu time 0.01 seconds
6
7 data class_copy;
8 set class;
9 run;
NOTE: View WORK.CLASS.VIEW used (Total process time):
real time 0.09 seconds
cpu time 0.01 seconds
NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: There were 19 observations read from the data set WORK.CLASS.
NOTE: The data set WORK.CLASS_COPY has 19 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 0.15 seconds
cpu time 0.04 seconds
10
11 proc contents data=class_copy;
12 run;
NOTE: PROCEDURE CONTENTS used (Total process time):
real time 0.01 seconds
cpu time 0.00 seconds
The resulting CLASS_COPY dataset is using the UTF-8 encoding.
@Tom, you are running in sas environment already defined with encodig=utf-8.
The problem arised when a mass of datasets were created with encoding=Latin1 but need be
converted to encoding=utf-8.
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!
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.