BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
sassy_seb
Fluorite | Level 6
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

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 16 replies
  • 484 views
  • 10 likes
  • 4 in conversation