BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jeremy4
Quartz | Level 8

Hi,

 

I would like to use proc sql to create a table and do a left join between two datasets - I have the following two lines to start off with so far:

 

proc sql;

create table NEV_TIME_ON_BOOK as

 

Steps to be completed:

 

1. Variables to select from datasets A and B:

Dataset cdpview.card_2019 as A - select:

account_ID, month_end, time_on_book

 

Dataset cdpview.output_2019 as B - select:

account_ID, month_end, portfolio_segment

 

2. Left join

I would like to do a left join:

 

cdpview.card_2019 as A
left join cdpview.output_2019 as B
on a.account_id = B.account_id and a.mth_end = b.mth_end

 

3. Only see results where portfolio_segment='NEV'

Also, from dataset B (cdpview.output_2019), I would only want to see results where portfolio_segment='NEV'.

 

Is there code so that once the left join has been done, the table NEV_TIME_ON_BOOK:

1. Lists the 'time_on_book' results for each of the records where portfolio_segment='NEV'.

2. The table is ordered by account_ID.

 

Thanks in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
gamotte
Rhodochrosite | Level 12

Hello,

 

You have given all the elements. Putting them together gives :

 

proc sql;
    create table NEV_TIME_ON_BOOK as
    select a.account_ID, a.month_end, a.time_on_book, b.portfolio_segment
    from cdpview.card_2019 as a
    left join cdpview.output_2019 as b
    on a.account_id = b.account_id and a.month_end = b.month_end
    where b.portfolio_segment='NEV'
    order by a.account_ID
    ;
quit;

I assumed mth_end was a typo for month_end.

View solution in original post

1 REPLY 1
gamotte
Rhodochrosite | Level 12

Hello,

 

You have given all the elements. Putting them together gives :

 

proc sql;
    create table NEV_TIME_ON_BOOK as
    select a.account_ID, a.month_end, a.time_on_book, b.portfolio_segment
    from cdpview.card_2019 as a
    left join cdpview.output_2019 as b
    on a.account_id = b.account_id and a.month_end = b.month_end
    where b.portfolio_segment='NEV'
    order by a.account_ID
    ;
quit;

I assumed mth_end was a typo for month_end.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 646 views
  • 0 likes
  • 2 in conversation