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
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.