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

I have a data a:

with a lot variables a b c d e...etc. for example, I want to combine with dataset b with variable named "X". but one row of b might have around 30,000 matched "X" in a.

my SAS code is:

proc sql noprint;

create table ds as

select a.*, b.momstatefips

from a left join b

on a.momstatefips1=b.momstatefips;

quit;

Is this code right? It always takes a long time to run this code and give me the note that "out of resource". Does that make sense???

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Maybe you are trying to subset dataset a to extract the rows that are mentioned in dataset b? If so, use

proc sql;

create table ds as

select a.*

from a inner join b

on a.momstatefips1 = b.momstatefips;

quit;

PG

PG

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

What are you actually trying to do?  Your current step is not adding any information since you are only selecting that variable that already matches the existing variable.

If you are doing a 1 to Many merge then use data step with a merge statement instead.

Below is the data step equivalent of your left join, plus I added the variable FOUND to indicate if there was a match. 

Note that it will only work if your data is sorted.


data DS ;

  merge MOMSTATEFIPS (in=in1 rename=(MOMSTATEFIPS1 =  MOMSTATEFIPS)) B (keep=MOMSTATEFIPS in=in2) ;

  by MOMSTATEFIPS;

  if in1 ;

  FOUND= in2;

run;

PGStats
Opal | Level 21

Maybe you are trying to subset dataset a to extract the rows that are mentioned in dataset b? If so, use

proc sql;

create table ds as

select a.*

from a inner join b

on a.momstatefips1 = b.momstatefips;

quit;

PG

PG
AmitRathore
Obsidian | Level 7

Hi Experts,

Using an index in table momstatefips1 is one of options to reduce the processing time.

An index can reduce the time required to locate a set of rows, especially for a large data file.


proc sql noprint;

  create index x on work.momstatefips1(x);

  create table ds as

  select a.*

  from a inner join b

  on a.momstatefips1 = b.momstatefips;

quit;

Br, Amit

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 842 views
  • 0 likes
  • 4 in conversation