Here you go. This is simplified to only consider character extended attributes.
data class;
set sashelp.class;
run;
ods select none;
PROC DATASETS LIBRARY=WORK nolist;
MODIFY class;
XATTR SET VAR
NAME (Values="Name - Missing")
SEX (Values='SEX - Not Missing')
AGE (Range='teenagers')
;
run;
ods output ExtendedAttributesVar=Xattr ;
contents data=class out=contents;
quit;
ods select all;
proc sort data=xattr;
by member AttributeVariable ExtendedAttribute;
run;
proc transpose data=xattr out=xattr_wide(drop=_name_ _label_) ;
by member AttributeVariable;
id ExtendedAttribute;
var AttributeCharValue;
run;
proc sql;
create table my_casebook(drop=member AttributeVariable) as
select a.libname,a.memname,a.varnum,a.name,a.type,a.length,a.format,a.label
, b.*
from contents a
left join xattr_wide b
on a.libname = scan(b.member,1,'.')
and a.memname = scan(b.member,-1,'.')
and upcase(a.name) = b.AttributeVariable
order by 1,2,3
;
quit;
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.