BookmarkSubscribeRSS Feed
rezausc
Calcite | Level 5

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

5 REPLIES 5
ballardw
Super User

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?

rezausc
Calcite | Level 5

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

Reeza
Super User

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;

rezausc
Calcite | Level 5

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).

Reeza
Super User

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 1465 views
  • 3 likes
  • 3 in conversation