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
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.