BookmarkSubscribeRSS Feed

How to Join on Multiple Keys in a CAS View

Started ‎07-18-2021 by
Modified ‎07-18-2021 by
Views 3,549

The join functionality in a CAS View has been extended. You can now join tables on multiple keys since the SAS Viya 2020.1.3 stable cadence. Therefore, the changes are included in the 2021.1 long term support.


If you are not familiar with the star schemas in CAS, I recommend reviewing the following posts:



Before SAS Viya 2020.1.3



Select any image to see a larger version.
Mobile users: To view the images, select the "Full" version at the bottom of the page.


After SAS Viya 2020.1.3




You can now specify multiple join keys. For example, the customer code and the record source:


{keys={'m_customer_code = c_customer_code', 'm_record_source = c_record_source'}


To create a CAS View (the star schema in the second diagram), you could write:


cas mySession sessopts=(caslib="casuser" timeout=1800 locale="en_US" 
	metrics="true" dqLocale="(ENUSA)");
caslib _all_ assign;
* Multi-key join FACT + DIM 2 keys + DIM one key;
proc casutil;
droptable casdata="mail_view_multi" incaslib="casuser" quiet;
proc cas;
table.view / promote=true name='mail_view_multi'
{name='mailorder_mkey', varlist={'qty'}, as='m'},
{keys={'m_customer_code = c_customer_code', 'm_record_source = c_record_source'},
'region','state','zip'}, as='c'},
{keys={'m_pcode = p_pcode'},
name='products_rep',  varlist={'price', 'cost', 'descrip', 'type'},
computedVarsProgram="price_cost_ratio = price/cost;", as='p'},
{keys={'m_catcode = cat_catcode'},
name='catcode_rep', varlist={'catalog'}, as='cat'}
cas mySession terminate;

Note how the price cost ratio is defined as a calculation within the view.



Facts and dimensions tables loaded in CAS.



Special thanks to Gordon Keener in SAS R&D for his time, efforts, and sharing information on this topic.



I would recommend the following resources:



Thank you for your time reading this post. Please share your experience with the CAS Star Schemas and help others.


If you wish to get more information, please leave a comment.


Find more articles from SAS Global Enablement and Learning here.

Version history
Last update:
‎07-18-2021 10:22 PM
Updated by:



Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started