CAS is massively parallel, spreading its processing across multiple threads on multiple machines but this affects the way you need to write your CAS DATA Step code. Let's look at how we might choose to create a unique row identifier in CAS versus SAS.
Creating a unique ID in SAS DATA Step is quite simple. We just use the _n_ automatic variable as shown below:
uniqueID = _n_;
Creating a unique ID in CAS DATA Step is more complicated. Each thread maintains its own _n_. So if we just use _n_, we'll get duplicate IDs. Each thread will produce an uniqueID field value of 1. Each thread will produce an uniqueID field value of 2. And so on.... When the thread output is combined, we'll have a bunch of records with a uniqueID of 1 and a bunch with a uniqueID of 2.... This is not useful. To produce a truly unique ID, you need to augment _n_ with something else. CAS has its own set of automatic variables for such purposes. The _threadID_ automatic variable can help us get our unique ID as shown below:
uniqueID = put(_threadid_,8.) || '_' || Put(_n_,8.);
While there are surely other ways of doing it, concatenating _threadID_ with the _n_ ensures uniqueness because the _threadID_ uniquely identifies a single thread and _n_ uniquely identifies a single row output by that thread.
For more information on threads and CAS DATA Step, see this blog post.
Time is running out to save with the early bird rate. Register by Friday, March 1 for just $695 - $100 off the standard rate.
Check out the agenda and get ready for a jam-packed event featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events.
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.