BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
sassy_seb
Quartz | Level 8
This is super useful, and I have used it already. I am just trying to do some work myself so I can learn how SAS works. Macros are still fairly new, but I appreciate all of the help! You mentioned previously I could add a format correct? Can I save that as a separate .sas program and include it in this one?
Tom
Super User Tom
Super User

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;

Tom_0-1714069994088.png

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 16 replies
  • 4462 views
  • 10 likes
  • 4 in conversation