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

Hi guys. I have two columns value1 and value2, in value1, say, I have three observations a, b, c, in value2, I have 4 observations a, a, b,m, I want to create a dummy variable match for each row in value1, if the value can be found in value 2, then match=1 otherwise it is 0. So for this dataset, it should be 1,1,0. Can anyone help me with this? Thanks a lot!

1 ACCEPTED SOLUTION

Accepted Solutions
user24feb
Barite | Level 11

Data A;
  Input value1 $ value2 $;
  Datalines;
a a
b a
c b
. m
;
Run;

Data B;
  If _N_ eq 1 Then Do;
    Declare Hash H (Dataset:'A (Drop=value1 Rename=(value2=value1)');
 H.Definekey('value1');
 H.Definedone();
 If 0 Then Set A (Drop=value1 Rename=(value2=value1));
  End;
  Set A;
  dummy=1-Min(H.Find(),1);
Run;

View solution in original post

4 REPLIES 4
user24feb
Barite | Level 11

Data A;
  Input value1 $ value2 $;
  Datalines;
a a
b a
c b
. m
;
Run;

Data B;
  If _N_ eq 1 Then Do;
    Declare Hash H (Dataset:'A (Drop=value1 Rename=(value2=value1)');
 H.Definekey('value1');
 H.Definedone();
 If 0 Then Set A (Drop=value1 Rename=(value2=value1));
  End;
  Set A;
  dummy=1-Min(H.Find(),1);
Run;

PaigeMiller
Diamond | Level 26

Use PROC GLMMOD to create dummy variables.

--
Paige Miller

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 1484 views
  • 2 likes
  • 3 in conversation