Help using Base SAS procedures

Use label to subset my data

Reply
New Contributor
Posts: 3

Use label to subset my data

I have a dataset with over thousands of columns and millions of records. I don't need all the columns (need all the rows) and want to subset my dataset by keeping columns that have specific labels. So, the subsetting is not based on column or var names.... it's based on their labels. Any idea how to do it efficiently?

Thanks

Super User
Posts: 10,483

Re: Use label to subset my data

Do the labels of the variables you want to keep (or drop) have any unique characteristics such as a word or phrase(s) that do not occur in the labels of the other variables?

Or do you have an existing list of the labels you want to keep?

New Contributor
Posts: 3

Re: Use label to subset my data

Yes. I'm looking for specific label (contains specific term). But the variables with this label are distributed across all vars.

Super User
Posts: 17,784

Re: Use label to subset my data

Create a macro variable with the variable names by querying the dictionary.table with search for the specific label column.

proc sql;

     select name into :vlist separated by " "

from dictionary.tables where libname ='SASHELP" and memname="CLASS" and upcase(label) contains "YOUR CRITERIA";

quit;

data want;

set have (keep= &vlist);

run;

New Contributor
Posts: 3

Re: Use label to subset my data

Sorry, but I'm a newbie to SAS... Not very familiar with dictionary.tables. When I ran your code, I got ths error:

ERROR: The following columns were not found in the contributing tables: name.

By the way, I'm running SAS in command line (no gui).

Super User
Posts: 17,784

Re: Use label to subset my data

Try googling dictionary tables sas and you'll find a lot of references to them.

SAS(R) 9.2 Language Reference: Concepts, Second Edition

Sorry, I pointed you to the wrong table. It is the sashelp.vcolumn or dictionary.columns table instead.

You can run a proc contents on this table to see the column names and even a proc print to see some of the data.

Check

proc sql;

     select name into :vlist separated by " "

from dictionary.columns where libname ='SASHELP" and memname="CLASS" and upcase(label) contains "YOUR CRITERIA";

quit;

data want;

set have (keep= &vlist);

run;

Ask a Question
Discussion stats
  • 5 replies
  • 225 views
  • 3 likes
  • 3 in conversation