Help using Base SAS procedures

how to make this result possible?

Reply
Frequent Contributor
Posts: 89

how to make this result possible?

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?
Super Contributor
Posts: 578

Re: how to make this result possible?

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;
Frequent Contributor
Posts: 89

Re: how to make this result possible?

thank you very much.

Have a nice holiday.
Ask a Question
Discussion stats
  • 2 replies
  • 251 views
  • 0 likes
  • 2 in conversation