BookmarkSubscribeRSS Feed
SuzyG_
Calcite | Level 5

We use proc compare to validate dataset output--that both datasets have the same records, same number of variables, and all values match.  But is there a fast-n-easy way to compare the *order* of the variables?  If I have one dataset with columns left to right VAR1 VAR2 VAR3, and another dataset with columns left to right VAR2 VAR3 VAR1, proc compare only catches if there is a difference in the values or number of records.  I'm looking for a way to validate that the variables are in the order we expect, and just wondered if there was a SAS option or command or macro that will do this quickly?

Many thanks,

Suzy

3 REPLIES 3
ursula
Pyrite | Level 9

you can do:

data new;

retain VAR1 VAR2 VAR3;

set existing_data;run;

hope it helps!

Jagadishkatam
Amethyst | Level 16

Hi Suzy,

The way i know is the use of proc contents, output dataset with variable name and order. Then comparing the two datasets. Hope it helps

data test;

   d=2;

   b001 =1;

   b002 =2;

   b003 =3;

   b001z=1;

   B001a=2;

   CaSeSeNsItIvE2=9;

   CASESENSITIVE3=9;

   D=2;

   casesensitive1=9;

   CaSeSeNsItIvE1a=9;

   d001z=1;  

   CASESENSITIVE1C=9;

   D001a=2;  

   casesensitive1b=9; 

   A =1;

   a002 =2;

   a =3;

   a001z=1;

   A001a=2;

run;

data test2;

    casesensitive1=9;

   CaSeSeNsItIvE1a=9;

   d001z=1;  

   CASESENSITIVE1C=9;

   D001a=2;  

   casesensitive1b=9; 

   A =1;

   a002 =2;

   a =3;

   a001z=1;

   A001a=2;

   d=2;

   b001 =1;

   b002 =2;

   b003 =3;

   b001z=1;

   B001a=2;

   CaSeSeNsItIvE2=9;

   CASESENSITIVE3=9;

   D=2;

run;

proc contents data=test out=ord(keep=name varnum) order=varnum;

run;

proc contents data=test2 out=ord2(keep=name varnum) order=varnum;

run;

proc compare base=ord compare=ord2 listall;

id name;

run;

Thanks,

Jag

Thanks,
Jag
PGStats
Opal | Level 21

One way to get a list of out of order variables:

proc sql;

create table expect (var1 real, var2 real, var3 real);

create table other  (var2 real, var3 real, var1 real);

quit;

title "Variables out of order in dataset OTHER";

proc sql;

select *

from

(   select name, varnum "Wrong Order" from dictionary.columns

    where libname = "WORK" and memname="OTHER" )

except

(   select name, varnum from dictionary.columns

    where libname = "WORK" and memname="EXPECT" );

quit;

PG

PG

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1906 views
  • 1 like
  • 4 in conversation