Selecting variables and transferring into new dataset's in SAS

sas
data_wrangling

#1

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?


#2

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


#3

@zubairsahil

Hi,

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

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

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;
Run;

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

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

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

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

Regards,
Sunil


#4

yeah…
its working, thank you Sir !