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.

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!

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.

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