BookmarkSubscribeRSS Feed
DubsNU
Calcite | Level 5

Hi all,

I have two SAS datasets with different variable names. I need to pull all the rows in dataset that match a value in the other dataset. One variable name is account with the other being custaccount. There are 150 or so values in custaccount that can all be found in the other dataset in account. I want to pull all the data attached to account using custaccount as a key. There must be an incredibly simple way to do this, I am still learning. Thanks all.


3 REPLIES 3
art297
Opal | Level 21

You have to be clearer regarding what you want.  If one dataset is called "one" and it contains an id variable called account (plus 150 or so other variables), and the other is called "two" and it contains a variable called custaccount (plus the same 150 or so other variables), do you just want to select the records from one whose account id is in two but called custaccount?  Are there multiple records for account and/or custaccount in either of the files?  Are you interested in the remaining 150 or so variables from either of the files?

Reeza
Super User

PROC SQL is one of the simplest to write and understand IMO

proc sql;

     create table all_accounts as

     select *

     from table1

      where account in

          (select distinct custaccount from table2);

quit;

DubsNU
Calcite | Level 5

Excellent. That works perfectly. Thank you so much.

sas-innovate-2024.png

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.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 523 views
  • 0 likes
  • 3 in conversation