I Have Created a Dataset as
RF101 | 101 | 10001 | ALPHA | XABC | RF10110110001 |
RF101 | 101 | 10001 | BETA | XABC | RF10110110001 |
RF101 | 101 | 10001 | GAMMA | RFAB | RF10110110001 |
RF101 | 101 | 10002 | GAMMA | GAG | RF10110110002 |
RF101 | 101 | 10002 | ZURO | MAM | RF10110110002 |
RF101 | 101 | 10002 | GAAFAZ | GAG | RF10110110002 |
RF101 | 101 | 10002 | XELFO | MAM | RF10110110002 |
And i Sorted the dataset as
RF101 | 101 | 10001 | GAMMA | RFAB | RF10110110001 |
RF101 | 101 | 10001 | ALPHA | XABC | RF10110110001 |
RF101 | 101 | 10001 | BETA | XABC | RF10110110001 |
RF101 | 101 | 10002 | GAAFAZ | GAG | RF10110110002 |
RF101 | 101 | 10002 | GAMMA | GAG | RF10110110002 |
RF101 | 101 | 10002 | XELFO | MAM | RF10110110002 |
RF101 | 101 | 10002 | ZURO | MAM | RF10110110002 |
I Want the Obersvation Number of the dataset (which is not sorted) in the Output dataset in a Variable called Result
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.
Could You write the Code How to assgin it.
Create your 'Result' variable thus
Data Coded ;
Set Original ;
Result = _N_ ;
Run ;
Then sort it.
Richard
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.