BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.

Hi all,

I have a dataset

A B C D E
1 2 3 1 2
1 2 3 1 2
1 2 3 1 2
1 2 3 1 2
1 2 3 1 2

 

I have to run a code in such a way that it should give me the list of fields that are 100%matched in one output

ex:

A,D

B,E are same

 

There is any way I can do it.

 

Thanks

 

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Thanks for the quick reply. Given this information, I would recommend that you run the suggested code. This will give you the comparisons for numeric variables. Then, to accomplish the same for the character variables, you simply add var _character_; to the first PROC TRANSPOSE step:

proc transpose data=have out=trans;
var _character_;
run;

 

Edit: This assumes that you are not looking for character variables containing "numeric" values which are equal to the values of one of the numeric variables.

View solution in original post

5 REPLIES 5
FreelanceReinh
Jade | Level 19

I think, there is a variety of possible approaches. For your sample data the following simple approach works:

data have;
input A B C D E;
cards;
1 2 3 1 2
1 2 3 1 2
1 2 3 1 2
1 2 3 1 2
1 2 3 1 2
;

proc transpose data=have out=trans;
run;

proc sort data=trans nouniquekey;
by col:;
run;

proc transpose data=trans prefix=var out=want(keep=var:);
by col:;
var _name_;
run;

proc print data=want;
run;

Does your real dataset contain character variables? How many observations and variables does it have?

siddharthpeesary
Calcite | Level 5
yeah I also have character variables
FIELDS= 100+
RECORDS=1000-2000
FreelanceReinh
Jade | Level 19

Thanks for the quick reply. Given this information, I would recommend that you run the suggested code. This will give you the comparisons for numeric variables. Then, to accomplish the same for the character variables, you simply add var _character_; to the first PROC TRANSPOSE step:

proc transpose data=have out=trans;
var _character_;
run;

 

Edit: This assumes that you are not looking for character variables containing "numeric" values which are equal to the values of one of the numeric variables.

siddharthpeesary
Calcite | Level 5
Thank you so much ...It worked 🙂
Ksharp
Super User

That would be very easy if you switch into IML code .

 

 

data have;
input A B C D E;
cards;
1 2 3 1 2
1 2 3 1 2
1 2 3 1 2
1 2 3 1 2
1 2 3 1 2
;
run;
proc iml;
use have;
read all var _ALL_ into x[c=vnames];
close;
do i=1 to ncol(x);
 match=vnames[i];
 found=0;
 do j=i+1 to ncol(x);
  if all(x[,i]=x[,j]) then do;match=catx(' ',match,vnames[j]);found=1;end;
 end;
 if found then print match;
end;
quit;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 5 replies
  • 834 views
  • 0 likes
  • 3 in conversation