How to display the old Obervation Number in the dataset when dataset is sorted

Reply
Contributor
Posts: 32

How to display the old Obervation Number in the dataset when dataset is sorted

I Have Created a Dataset as

RF10110110001ALPHAXABCRF10110110001
RF10110110001BETAXABCRF10110110001
RF10110110001GAMMARFABRF10110110001
RF10110110002GAMMAGAGRF10110110002
RF10110110002ZUROMAMRF10110110002
RF10110110002GAAFAZGAGRF10110110002
RF10110110002XELFOMAMRF10110110002

And i Sorted the dataset as

RF10110110001GAMMARFABRF10110110001
RF10110110001ALPHAXABCRF10110110001
RF10110110001BETAXABCRF10110110001
RF10110110002GAAFAZGAGRF10110110002
RF10110110002GAMMAGAGRF10110110002
RF10110110002XELFOMAMRF10110110002
RF10110110002ZUROMAMRF10110110002

I Want the Obersvation Number of the dataset (which is not sorted) in the Output dataset in a Variable called Result

Super User
Posts: 5,255

Re: How to display the old Obervation Number in the dataset when dataset is sorted

Well, then you have to store the original sort order in a column. Using SQL order by, you could use the monotonic() function, or assign it to _N_ in a data step prior to sorting.

Data never sleeps
Contributor
Posts: 32

Re: How to display the old Obervation Number in the dataset when dataset is sorted

Could You write the Code How to assgin it.

Super Contributor
Posts: 644

Re: How to display the old Obervation Number in the dataset when dataset is sorted

SushilKumar


Create your 'Result' variable thus

     Data Coded ;

          Set Original ;

               Result = _N_ ;

     Run ;

Then sort it.

Richard

Ask a Question
Discussion stats
  • 3 replies
  • 233 views
  • 1 like
  • 3 in conversation