Hi Friends,
I need to capture the encoding type of dataset in 1 macro variable for further process.
Proc contents is displaying encoding type in .lst file . I need to capture it in one variable .
Can we find encoding type of dataset in any internal SAS metadata dataset ?
Thanks,
Sasikala.k
Hi @sasikala
something like this?
data _null_;
set sashelp.vtable;
where lowcase(libname)="my_lib" and lowcase(memname)="my_dataset"; /*specify your library and your dataset names*/
call symputx("encoding",encoding);
run;
%put &encoding;
You can try using the dictionary tables, e.g.:
proc sql noprint;
select
encoding
into
:encoding
from
dictionary.tables
where
libname eq 'SASHELP'
and memname eq 'CLASS'
;
quit;
%put encoding = &encoding;
Regards,
Amir.
You can use ODS OUTPUT to have SAS save a dataset out of the information it prints. (Use ODS TRACE to figure out what the outputs are named).
ods output attributes=attributes;
proc contents data=sashelp.class; run;
proc print data=attributes; run;
data _null_;
set attributes;
where label1='Encoding';
call symputx('encoding',cValue1);
run;
Or you can query the metadata table TABLES.
proc sql;
select libname,memname,encoding
from dictionary.tables where libname='SASHELP' and memname='CLASS'
;
proc sql noprint;
select encoding into :encoding trimmed
from dictionary.tables where libname='SASHELP' and memname='CLASS'
;
But you might want to remove the descriptive part of that text if you want a value you could actually use in code.
%let encoding=%scan(&encoding,-1,());
Thanks All !.
Hi Guys !
One more requirement, I needed get the CPORT or XPORT file encoding and store it in another variable .
Any idea ?
Thanks,
Sasikala.k
Does the XPORT format even support encoding?
47 filename x temp; 48 libname x xport; NOTE: Libref X was successfully assigned as follows: Engine: XPORT Physical Name: ...\#LN00057 49 data x.class(encoding='utf8'); set sashelp.class; run; -------- 76 WARNING 76-63: The option ENCODING is not implemented in the XPORT engine. NOTE: There were 19 observations read from the data set SASHELP.CLASS. NOTE: The data set X.CLASS has 19 observations and 5 variables. NOTE: DATA statement used (Total process time): real time 0.04 seconds cpu time 0.00 seconds
For CPORT files you will probably need to first use CIMPORT to create actual datasets out of them and then check that dataset's encoding.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.