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

Hi, all

I want to merge to datasets

data1 has VAR1 VAR2 VAR3 year

data2 has VAR1 VAR2 VAR4 VAR 5 year

I use proc sql left join data1 with data2 with the following conditions :

data1.var1=data2.var1

1993<year<2000

i got error using the code below:

proc sql;
create table WANT as select
A.*, B.*
From DATA1 as A left join DATA2 as B
WHERE 1993<=YEAR<=2000
On A.VAR1 =B.VAR2
order by VAR1, year;

quit;

please help and Thanks!

Lan

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Let me try to guess and at least give you a starting point :

proc sql;
create table WANT as select
A.*, B.VAR4, B.VAR5
From DATA1 as A left join DATA2 as B

     on A.VAR1=B.VAR1 and A.VAR2=B.VAR2 and A.year=B.year
WHERE A.year between 1993 and 2000
order by VAR1, year;

select * from WANT;

quit;

PG

PG

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

Which of the two YEAR variables do you want to subset on?

Perhaps you want to add the condition that A.year = B.year ? 

Since you are doing a LEFT JOIN perhaps you want to subset on A.year ? Or perhaps both?

PGStats
Opal | Level 21

Let me try to guess and at least give you a starting point :

proc sql;
create table WANT as select
A.*, B.VAR4, B.VAR5
From DATA1 as A left join DATA2 as B

     on A.VAR1=B.VAR1 and A.VAR2=B.VAR2 and A.year=B.year
WHERE A.year between 1993 and 2000
order by VAR1, year;

select * from WANT;

quit;

PG

PG

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
  • 2 replies
  • 854 views
  • 0 likes
  • 3 in conversation