<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Merging with dummy datasets in SAS Studio</title>
    <link>https://communities.sas.com/t5/SAS-Studio/Merging-with-dummy-datasets/m-p/875652#M10951</link>
    <description>&lt;PRE&gt;data temp;
 length name $20.;
 length present $15.;
 Present="Y";
 
 do visit=1,2,3,4,8,10,15;
  name='Namea';
  output;
 end;
 
 do visit=2,15;
  name='Nameb';
  output;
 end;
 
 do visit=1,2,5,7,10,11,12,13,14,15;
  name='Namec';
  output;
 end;
 
 do visit=1,2,10,11,14,15;
  name='Named';
  output;
 end;
 
 do visit=1 to 15;
  name='Namee';
  output;
 end;
run;

proc sort data=temp out=temps nodupkey;
 by name;
run;

data dummy; 
 set temps(keep=name);
  do lesson=1 to 18;
  output;
 end;
run;

proc sort data=dummy out=dummys nodup;
 by name;
run;

data merged;
 merge temps(in=a) dummys(in=b);
 by name;
 if a=b then present="Y";
 else present="N";
run;&lt;/PRE&gt;&lt;P&gt;Hello. My task is this: "The internship consists of 18 lessons. Create new variable named "present"&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;and set to “Y” if student was present in that lesson or set to “N” if student was absent. "&lt;BR /&gt;I tried this code but it didn't work,can you help to correct it?&lt;/P&gt;</description>
    <pubDate>Sun, 14 May 2023 11:37:02 GMT</pubDate>
    <dc:creator>Andrew15</dc:creator>
    <dc:date>2023-05-14T11:37:02Z</dc:date>
    <item>
      <title>Merging with dummy datasets</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Merging-with-dummy-datasets/m-p/875652#M10951</link>
      <description>&lt;PRE&gt;data temp;
 length name $20.;
 length present $15.;
 Present="Y";
 
 do visit=1,2,3,4,8,10,15;
  name='Namea';
  output;
 end;
 
 do visit=2,15;
  name='Nameb';
  output;
 end;
 
 do visit=1,2,5,7,10,11,12,13,14,15;
  name='Namec';
  output;
 end;
 
 do visit=1,2,10,11,14,15;
  name='Named';
  output;
 end;
 
 do visit=1 to 15;
  name='Namee';
  output;
 end;
run;

proc sort data=temp out=temps nodupkey;
 by name;
run;

data dummy; 
 set temps(keep=name);
  do lesson=1 to 18;
  output;
 end;
run;

proc sort data=dummy out=dummys nodup;
 by name;
run;

data merged;
 merge temps(in=a) dummys(in=b);
 by name;
 if a=b then present="Y";
 else present="N";
run;&lt;/PRE&gt;&lt;P&gt;Hello. My task is this: "The internship consists of 18 lessons. Create new variable named "present"&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;and set to “Y” if student was present in that lesson or set to “N” if student was absent. "&lt;BR /&gt;I tried this code but it didn't work,can you help to correct it?&lt;/P&gt;</description>
      <pubDate>Sun, 14 May 2023 11:37:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Merging-with-dummy-datasets/m-p/875652#M10951</guid>
      <dc:creator>Andrew15</dc:creator>
      <dc:date>2023-05-14T11:37:02Z</dc:date>
    </item>
    <item>
      <title>Re: Merging with dummy datasets</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Merging-with-dummy-datasets/m-p/875951#M10961</link>
      <description>Why are you using 'visit' for temps and 'lesson' for dummys?&lt;BR /&gt;In the merge step you check if name in temps is equal to name in dummys and you set present to "Y". That is not correct because if I understood you correctly you want to set present by name and lesson/visit. Please have another go with the tips I've given you here.</description>
      <pubDate>Tue, 16 May 2023 09:52:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Merging-with-dummy-datasets/m-p/875951#M10961</guid>
      <dc:creator>JosvanderVelden</dc:creator>
      <dc:date>2023-05-16T09:52:59Z</dc:date>
    </item>
    <item>
      <title>Re: Merging with dummy datasets</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Merging-with-dummy-datasets/m-p/875959#M10962</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
 length name $20.;
 length present $15.;
 Present="Y";
 
 do visit=1,2,3,4,8,10,15;
  name='Namea';
  output;
 end;
 
 do visit=2,15;
  name='Nameb';
  output;
 end;
 
 do visit=1,2,5,7,10,11,12,13,14,15;
  name='Namec';
  output;
 end;
 
 do visit=1,2,10,11,14,15;
  name='Named';
  output;
 end;
 
 do visit=1 to 15;
  name='Namee';
  output;
 end;
run;

proc sort data=temp out=temps nodupkey;
 by name visit;
run;

data dummy; 
 set temps(keep=name);
  do lesson=1 to 18;
  output;
 end;
run;

proc sort data=dummy out=dummys nodup;
 by name lesson;
run;

data merged;
 merge temps(in=a) dummys(in=b rename=(lesson=visit));
 by name visit;
 if a=b then presentCheck="Y";
 else presentCheck="N";
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 May 2023 10:09:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Merging-with-dummy-datasets/m-p/875959#M10962</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-05-16T10:09:38Z</dc:date>
    </item>
    <item>
      <title>Re: Merging with dummy datasets</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Merging-with-dummy-datasets/m-p/875988#M10963</link>
      <description>&lt;P&gt;So if you have this list of NAME/VISIT combinations.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
 infile cards truncover ;
 input name $ visit @ ;
 do while(visit ne .);
   output;
   input visit @;
 end;
cards;
A 1 2 3 4 8 10 15
B 2 15
C 1 2 5 7 10 11 12 13 14 15
D 1 2 10 11 14 15
E 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And you want to generate data that has 18 visits for every NAME you can just use a step like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dummy;
  set temp;
  by name;
  if first.name ;
  do visit=1 to 18;
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you can merge then and use the IN= flag from the original HAVE datasets to create your PRESENT varaible.&lt;/P&gt;
&lt;P&gt;Personally I find 0/1 variables easier to work with then N/Y variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  merge dummy temp(in=actual);
  by name visit;
  present=actual;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1684241726327.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/84012i2E83AB540AFCD595/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1684241726327.png" alt="Tom_0-1684241726327.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2023 12:55:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Merging-with-dummy-datasets/m-p/875988#M10963</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-16T12:55:33Z</dc:date>
    </item>
    <item>
      <title>Re: Merging with dummy datasets</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Merging-with-dummy-datasets/m-p/875990#M10964</link>
      <description>&lt;P&gt;Note that this A=B trick:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; merge A(in=a) B(in=b) ;
   by ...;
   if a=b then ...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Will only work when you are merging exactly two datasets.&lt;/P&gt;
&lt;P&gt;It works when there are two datasets because only 3 of the possible combinations of the two binary variables can exist since if A and B cannot both be zero (false) since then there would not be any observation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But once you introduce another source dataset then both A and B could be false, in which case their values will be equal.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If is much clearer to just use&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if a and b then ...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to save typing two letters you could use &amp;amp; to represent AND.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if a &amp;amp; b then ...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but that is also going to be cause the programmer reviewing the code to have to slow down and remember that &amp;amp; means AND.&lt;/P&gt;</description>
      <pubDate>Sun, 28 May 2023 15:24:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Merging-with-dummy-datasets/m-p/875990#M10964</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-28T15:24:10Z</dc:date>
    </item>
    <item>
      <title>Re: Merging with dummy datasets</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Merging-with-dummy-datasets/m-p/877898#M10981</link>
      <description>&lt;P&gt;Data TEMP, as you constructed it, is already sorted by name.&amp;nbsp; So:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  array classes {18}  _temporary_ ;
  set temp;
  by name;

  if first.name then call missing(of classes{*});
  classes{visit}=1;

  if last.name;
  do visit=lbound(classes) to hbound(classes);
    present=ifc(classes{visit}=1,'Y','N');
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 28 May 2023 04:21:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Merging-with-dummy-datasets/m-p/877898#M10981</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-05-28T04:21:56Z</dc:date>
    </item>
    <item>
      <title>Re: Merging with dummy datasets</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Merging-with-dummy-datasets/m-p/877901#M10982</link>
      <description>&lt;P&gt;I would write the condition like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;present = ifc(a and b,"Y","N");&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 28 May 2023 06:14:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Merging-with-dummy-datasets/m-p/877901#M10982</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-05-28T06:14:54Z</dc:date>
    </item>
  </channel>
</rss>

