Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting variables by label status

Status
Not open for further replies.

janelange

Technical User
Jun 12, 2003
45
US
I'm fairly new to SAS (but have some programming experience), and have what I hope is a pretty basic question:

I have a dataset with hundreds of variables, some of which have labels, some of which don't. Is there anyway to sort the variables themselves on the basis of whether or not they are labelled? (I.E. so I generate a list of variables without labels).

Thanks,
Jane L.

 
Yes! You can. You need to use some Dictionary tables. I'll just look it up and post the details here.
 
OK, here it is. Run this code to see the results:-
Code:
proc sql;
    create table WORK.dbcols as
    select *
    from dictionary.columns
    where libname='SASHELP' and memname='AIR'
    ;
quit;
This should run without problems as the SASHELP tables are installed with SAS. There is a column called "Label" which will give you the label for the column. Just change the libname and member name accordingly.
Things to note:-
1- libnames and member (dataset) names are in uppercase.
2- Dictionary tables are not actually tables, but more like views. If you simply run "Select * from dictionary.columns" you will end up with a dataset containing a record for every single column for every dataset in every library that you have defined. This data is extracted when you request it, so if you have a library pointing to (for instance) a large oracle data warehouse, you could be waiting for some time for your results.
3 - Dictionary tables are READ ONLY, so you can't write back to them to change the labels I'm afraid.

There are numerous Dictionary tables which you can read up on on the SAS documentation site, the most useful ones are DICTIONARY.TABLES and DICTIONARY.COLUMNS. OPTIONS will give you the current system and user options etc.
Have fun!
 
hope this is not to late to be useful !
no programming - just point-n-click
Drill down the sas explorer window, to the table with all these variables, and in the columns view (get to that, by right click on the table and select "view columns"), click on the header of the label column

Of course, if you want to use the list of variables without labels as data (really metadata), follow the examples using dictionary.columns, or the out= option of proc contents.

Peter
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top