BookmarkSubscribeRSS Feed
Vijendra_SAS
Calcite | Level 5

usually we use Proc Compare for comparing two sas datasets and their observation, variable.

is there any way we can compare the observation with in single sas datasets with eachother ? which procedure we use ? what is syntax ?

please let me know ASAP

9 REPLIES 9
Reeza
Super User

That depends on what you're trying to do.

What are you trying to do? Compare one variable against another variable? Compare one row against a different/all rows?

Vijendra_SAS
Calcite | Level 5

hi

I am comparing one row against another row..

Reeza
Super User

There are ways to make proc compare do that, but you'll need to replicate your dataset and indicate which rows are compared against which.


It's probably easier to go with a manual data step or a sql step.

If you want further advice, you'll need to provide more detailed information.

Vijendra_SAS
Calcite | Level 5

i have file , I couldnot attach it to conversation.. let me know your mail id.. I can send it across.. and we can discuss

Reeza
Super User

No thanks, attach here (edit your first post), or preferably recreate a simple sample that you can paste into the window.

IE usually won't allow you to paste, so you might need to use FireFox or Chrome.

Vijendra_SAS
Calcite | Level 5

Hi

i tried to attach file in my first post, you may refer there , about what I want to know.

Vijendra_SAS
Calcite | Level 5

In attached file , I want to check if Field_Name across all the Form_Name have same definition or not ? if its varies even by space, comma or fullstop , my SAS program should give me out file with those difference.

I have applied filter , just for convenience of your understanding.

let me know which function I can use ?  ( I am aware of lag function.. but not able to put inform of sytax )

Reeza
Super User

You don't specify what you want your output to look like.

Sort your data by Field_Name and use first./last. processing in addition to the definition. If the definition varies while the field name is the same it will flag it.

I don't think this is quite right, but you can review the first/last processing and see what works for you.

proc sort data=have; by form_name field_name definition; run;

data want;

set have;

by form_name field_name;

if first.field_name and not (first.definition and last.definition) then flag=1;

else flag=0;

run;

Astounding
PROC Star

Maybe what you really want is as simple as this:

proc freq data=have;

   tables field_name;

run;

If not, it might be this:

proc freq data=have;

   tables form_name * field_name / missing list;

run;

It won't point out which rows you need to fix, but it will find the spelling variations.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 9 replies
  • 2470 views
  • 0 likes
  • 3 in conversation