Help using Base SAS procedures

Working on the SAS variable name only

Reply
Contributor
Posts: 56

Working on the SAS variable name only

Is there anyone know how to perform the data manipulation on the SAS variable name only?

So far, every time the performance that referred to a variable is on its data below the variable name. But wot if I only want to use that variable name for my purpose? ie.

TWO TWOVO TLE TLEVO TLC TLCVO
1 1
3 3
4 5
5 6

I want to delete the variable name contains 'VO', how can I do it?
Thanks
Regular Contributor
Posts: 221

Re: Working on the SAS variable name only

Examine the sashelp.vcolumn view. It contains everything you need to create a drop-statement for proc sql.
[pre]
proc sql noprint;
select name
into :kill_list separated by ','
from sashelp.vcolumn
where memname = upcase('NAME_OF_YOUR_DATASET') and index(upcase(name), 'VO') > 0;

alter table NAME_OF_YOUR_DATASET
drop &kill_list;
quit;
[/pre]

Untested.
Super Contributor
Posts: 474

Re: Working on the SAS variable name only

Hello Fred.

You could access to the metadata of the the table (say with proc contents or dictionary.columns), build a macro variable with the list of the desired columns and then perform a DROP of those (always rewriting the dataset).

/* get table info */
proc contents data = YOURDATA out = _CONTENTS noprint;
run;

/* buil DROPLIST */
%let DROPLIST=;
data _null_;
set _CONTENTS;
where index(upcase(NAME),'VO'); /* Var names who contains 'VO' */
call symput('DROPLIST',catx(' ',symget('DROPLIST'),NAME));
run;

/* rewrite the dataset and drop the desired Vars */
%put &DROPLIST;
data YOURDATA;
set YOURDATA;
drop &DROPLIST;
run;

Greetings from Portugal.

Daniel Santos at www.cgd.pt
Ask a Question
Discussion stats
  • 2 replies
  • 57 views
  • 0 likes
  • 3 in conversation