SAS : Reordering Variables

Live Online Training : SAS Programming with 50+ Case Studies

- Explain Programming Concepts in Simple English
- Live Projects
- Scenario Based Questions
- Job Placement Assistance
- Get 10% off till Oct 26, 2017
- Batch starts from October 28, 2017

Suppose you have two datasets with same named variables. You want the order of the variables to be same in both the datasets.

Let's create two datasets
data abc;
input a b c;
cards;
1 3 4
2 4 5
;
run;

data bac;
input b a c;
cards;
1 3 4
2 4 5
;
run;
SAS Code : Reordering Variables
proc sql noprint;
select name
into :reorder
separated by ' '
from dictionary.columns
where libname="WORK" and
memname="ABC"
order by name;
quit;

data bac;
retain &reorder.;
set bac;
run;
Note : Put library and dataset name in LIBNAME and MEMNAME (in caps) in the above code. RETAIN is used to reorder variables in a SAS dataset.

SAS Tutorials : 100 Free SAS Tutorials

About Author:

Deepanshu founded ListenData with a simple objective - Make analytics easy to understand and follow. He has close to 7 years of experience in data science and predictive modeling. During his tenure, he has worked with global clients in various domains like retail and commercial banking, Telecom, HR and Automotive.


While I love having friends who agree, I only learn from those who don't.

Let's Get Connected: Email | LinkedIn

Get Free Email Updates :
*Please confirm your email address by clicking on the link sent to your Email*

Related Posts:

1 Response to "SAS : Reordering Variables"

  1. Hi Deepanshu ,
    Will you please expalain above code a bit.

    ReplyDelete

Next → ← Prev