BookmarkSubscribeRSS Feed
sasikala
Obsidian | Level 7

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

7 REPLIES 7
ed_sas_member
Meteorite | Level 14

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;
Amir
PROC Star

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.

Tom
Super User Tom
Super User

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;

image.png

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'
;

image.png

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,());
sasikala
Obsidian | Level 7

Thanks All !.

sasikala
Obsidian | Level 7

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

Tom
Super User Tom
Super User

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.

sasikala
Obsidian | Level 7
Thanks Tom.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 972 views
  • 2 likes
  • 4 in conversation