Selecting variables and transferring into new dataset's in SAS

I have a SAS data-set with 100 variables. Now I need to keep only 52nd and 11th variable into two separate different SAS Data sets. i.e., 52nd var shud be in A1 dataset and 11th var shud be in A2 dataset?

How can I do this in SAS?

@zubairsahil : Hi , You can use Keep and drop function in SAS for variables and obs and firstobs for observations.Please try keep and drop fucntion for your query.



Below i have created a data set Sales with three variables Month, Sales and Profit.

Data Sales;
Input Month$ Sales Profit;
May 11 2

Here i want to create a data set, which has only second variable Sales. I have followed below steps to perform this.

Step-1 Variable names stored in data set Test.

Proc Contents data=Sales out=Test;

Step-2 Store second variable name to a variable vName.

Proc Sql;
Select name into :vName from test where Varnum=2;

Step-3 Used variable name as Macro variable name for Variable subsetting.

Data Split (Keep = &vName);
Set Sales;


1 Like

its working, thank you Sir !

© Copyright 2013-2019 Analytics Vidhya