BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Costasg
Calcite | Level 5

Hello,

 

I would like to remove some variables based on some criteria in their label. Specifically, I want to delete 'B' shares but these are only mentioned in the label and not in the name of the variable.

 

For example:

Name: INSTITUTO_ROSENBUCH_DE_BIOLOGIA

Label: INSTITUTO ROSENBUCH DE BIOLOGIA 'B'

 

The code I used to apply for names is the following, but how can I transform it to use it on labels (if possible)?

 

proc sql noprint;

    select trim(compress(name))
    into :drop_vars separated by ' '
    from SASHELP.VCOLUMN 
    where libname = upcase('WORK')
        and
            memname = upcase('Sample')
        and
            upcase(name) like '%ERROR%'
    ;
quit;

%put &drop_vars.;

data data2;
    set Sample;
    drop  &drop_vars.;
run;

 

Many thanks in advance!

 

1 ACCEPTED SOLUTION

Accepted Solutions
RahulG
Barite | Level 11
data have;
a=202;
label a ="temp new";
b=102;
label b="temp";
c=302;
label c ="var c";

run;

proc contents data =have out=contents;run;

proc sql;
select name into :var_list separated by ' '
from contents
where label ? 'temp';
quit;
%put &var_list;

data want;
set have;
drop &var_list;
run;

In the above code I am dropping columns that has temp in their label.

View solution in original post

3 REPLIES 3
Reeza
Super User

Hint: Open Your data source and see if label column is present. 

 

Change your last condition from name to your label criteria. If it has the quotes make sure to include them in your search. 

It would be a filter such as 

 

 

    label_column_name like  "% 'B'"

RahulG
Barite | Level 11
data have;
a=202;
label a ="temp new";
b=102;
label b="temp";
c=302;
label c ="var c";

run;

proc contents data =have out=contents;run;

proc sql;
select name into :var_list separated by ' '
from contents
where label ? 'temp';
quit;
%put &var_list;

data want;
set have;
drop &var_list;
run;

In the above code I am dropping columns that has temp in their label.

Costasg
Calcite | Level 5

Many thanks for your answers both!

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 892 views
  • 0 likes
  • 3 in conversation