BookmarkSubscribeRSS Feed
littlestone
Fluorite | Level 6
Dear All

Suppose I have following codes:

data test;
input ID Var1;
cards;
1 1
2 2
3 3
;
run;

data test2;
input IDX Var100;
cards;
100 100
200 200
400 400
;
run;

PROC SQL;
CREATE TABLE Combined AS
SELECT u1.*,
u2.*
FROM test as u1 FULL JOIN test2 as u2
ON u1.ID = (u2.IDX)/100
;
QUIT;


The created data set Combined look like:

ID Var1 IDX VAR100
1 1 100 100
2 2 200 200
3 3 . .
. . 400 400


Now I want to careate one more Variable, Say Var999 that tells whether the combined data contains data from both dataset test and dataset test2 so that the created data set Combined will look like:

ID Var1 IDX VAR100 Var999
1 1 100 100 1
2 2 200 200 1
3 3 . . 0
. . 400 400 0


Can someone tell me how to do it?
2 REPLIES 2
DBailey
Lapis Lazuli | Level 10
PROC SQL;
CREATE TABLE Combined AS
SELECT u1.*,
u2.*, case when u1.id is not null and u2.idx is not null then 1 else 0 end as Var999
FROM test as u1 FULL JOIN test2 as u2
ON u1.ID = (u2.IDX)/100
;
QUIT;
littlestone
Fluorite | Level 6
thank you very much.

Have a nice holiday.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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