Dropping a variable from a SAS dataset

Accepted Solution Solved
Reply
Contributor
Posts: 54
Accepted Solution

Dropping a variable from a SAS dataset

How do I drop a variable from a SAS dataset?


Accepted Solutions
Solution
a week ago
Valued Guide
Posts: 591

Re: Dropping a variable from a SAS dataset

Posted in reply to JohnSAScom

There are several way and depends on how you want it. You can use DROP= if you have only few variables to drop or KEEP= if there are more variables to drop and only few to keep. 

 

Here are some way:

/* Reads from the input, but doesn't output */
data class (drop=Name);
set sashelp.class;
run;

/* Doesn't read from the input, so it will not be in output */
data class ;
set sashelp.class(drop=Name);
run;

/* You can also use drop in Proc SQL */
proc sql;
create table class(drop=Name) as
select *
	from sashelp.class;
quit;
/* Similar to above */
proc sql;
create table class as
select Sex,Age,Height,Weight /* Name variable is dropped */
	from sashelp.class;
quit;

/* You Can also alter table */
proc sql;
create table class as
select *
	from sashelp.class;
quit;
proc sql;
alter table work.class
drop name;
quit;
Thanks,
Suryakiran

View solution in original post


All Replies
Super User
Posts: 10,244

Re: Dropping a variable from a SAS dataset

Posted in reply to JohnSAScom

Use the drop statement or the drop dataset option. Documentation can be found by searching for "sas drop variable" on google.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Contributor
Posts: 54

Re: Dropping a variable from a SAS dataset

Posted in reply to KurtBremser

Thanks Kurt.

Solution
a week ago
Valued Guide
Posts: 591

Re: Dropping a variable from a SAS dataset

Posted in reply to JohnSAScom

There are several way and depends on how you want it. You can use DROP= if you have only few variables to drop or KEEP= if there are more variables to drop and only few to keep. 

 

Here are some way:

/* Reads from the input, but doesn't output */
data class (drop=Name);
set sashelp.class;
run;

/* Doesn't read from the input, so it will not be in output */
data class ;
set sashelp.class(drop=Name);
run;

/* You can also use drop in Proc SQL */
proc sql;
create table class(drop=Name) as
select *
	from sashelp.class;
quit;
/* Similar to above */
proc sql;
create table class as
select Sex,Age,Height,Weight /* Name variable is dropped */
	from sashelp.class;
quit;

/* You Can also alter table */
proc sql;
create table class as
select *
	from sashelp.class;
quit;
proc sql;
alter table work.class
drop name;
quit;
Thanks,
Suryakiran
Contributor
Posts: 54

Re: Dropping a variable from a SAS dataset

Posted in reply to SuryaKiran

Thanks Surya.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 70 views
  • 0 likes
  • 3 in conversation