<?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 Re: Creating &amp;quot;dummy variable&amp;quot; from four different variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-quot-dummy-variable-quot-from-four-different-variables/m-p/60771#M13197</link>
    <description>hi ... using this ...&lt;BR /&gt;
&lt;BR /&gt;
data _1 _2 _3 _4;&lt;BR /&gt;
id = 10; output _1 _3 _4;&lt;BR /&gt;
id = 20; output _1 _2;&lt;BR /&gt;
id = 30; output _2 _3 _4;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
try this ...&lt;BR /&gt;
&lt;BR /&gt;
data all;&lt;BR /&gt;
length datasource $4;&lt;BR /&gt;
merge _1(in=a) _2(in=b) _3(in=c) _4(in=d);&lt;BR /&gt;
by id;&lt;BR /&gt;
datasource = catt(ifc(a,'A',''),ifc(b,'B',''),ifc(c,'C',''),ifc(d,'D',''));&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
and get ...&lt;BR /&gt;
&lt;BR /&gt;
Obs    datasource    id&lt;BR /&gt;
 1        ACD        10&lt;BR /&gt;
 2        AB         20&lt;BR /&gt;
 3        BCD        30&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: MikeZdeb

Message was edited by: MikeZdeb</description>
    <pubDate>Thu, 13 Jan 2011 21:16:23 GMT</pubDate>
    <dc:creator>MikeZdeb</dc:creator>
    <dc:date>2011-01-13T21:16:23Z</dc:date>
    <item>
      <title>Creating "dummy variable" from four different variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-quot-dummy-variable-quot-from-four-different-variables/m-p/60768#M13194</link>
      <description>I have a single dataset with merged data from four different datasets. Problem is, some of the merged data is similar and I need to figure out who all has data from which of the original four datasets. There are four identifying variables DataA, DataB, DataC and DataD. If an individual has data from DataA present in the merged file then DataA = 1 else DataA = 0 and so on for the remaining three variables. What I am trying to do is create a single variable with different values depending on the datasource i.e. if an individual has data from DataA and DataB then datasource = AB, if an individual has data from DataA, DataC and DataD then datasource = ACD. Basically, there are several possibly combinations that can be present, only one datasource, two, three or four - all of which combinations cannot be repeating. I was trying to write code manually but it is taking a long time and can have errors. &lt;BR /&gt;
&lt;BR /&gt;
I tried to do a proc freq table to compare the four datasets, but I cannot seem to develop a table to see exactly what I would like to. Any help or advice is much appreciated! Thanks!</description>
      <pubDate>Mon, 10 Jan 2011 14:05:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-quot-dummy-variable-quot-from-four-different-variables/m-p/60768#M13194</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2011-01-10T14:05:29Z</dc:date>
    </item>
    <item>
      <title>Re: Creating "dummy variable" from four different variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-quot-dummy-variable-quot-from-four-different-variables/m-p/60769#M13195</link>
      <description>data _1 _2 _3 _4;&lt;BR /&gt;
	id = 10;&lt;BR /&gt;
	if id=10 then output _1 _3 _4;&lt;BR /&gt;
	id = 20;&lt;BR /&gt;
	if id=20 then output _1 _2;&lt;BR /&gt;
	id = 30;&lt;BR /&gt;
	if id=30 then output _2 _3 _4;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data all;&lt;BR /&gt;
	length datasource $4;&lt;BR /&gt;
	merge _1(in=a) _2(in=b) _3(in=c) _4(in=d);&lt;BR /&gt;
	by id;&lt;BR /&gt;
	if a then dataA='A';&lt;BR /&gt;
	if b then dataB='B';&lt;BR /&gt;
	if c then dataC='C';&lt;BR /&gt;
	if d then dataD='D';&lt;BR /&gt;
	datasource=cats(dataA,dataB,dataC,dataD);&lt;BR /&gt;
run;</description>
      <pubDate>Mon, 10 Jan 2011 14:43:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-quot-dummy-variable-quot-from-four-different-variables/m-p/60769#M13195</guid>
      <dc:creator>NickR</dc:creator>
      <dc:date>2011-01-10T14:43:32Z</dc:date>
    </item>
    <item>
      <title>Re: Creating "dummy variable" from four different variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-quot-dummy-variable-quot-from-four-different-variables/m-p/60770#M13196</link>
      <description>merge a(in=ina) b(in=inb) ...... ;&lt;BR /&gt;
&lt;BR /&gt;
fromD = put( ina*1000 + inb*100 +inc*10 +ind, z4. ) ;&lt;BR /&gt;
well, that is the underlying info&lt;BR /&gt;
You can write more processing to turn 0110 into BC, or just format it like :&lt;BR /&gt;
proc format ; value fromD &lt;BR /&gt;
1111 = ABCD &lt;BR /&gt;
1110 = ABC &lt;BR /&gt;
1101 = ABD&lt;BR /&gt;
1100 = AB&lt;BR /&gt;
1011 = ACD&lt;BR /&gt;
1010 = AC&lt;BR /&gt;
1001 = AD&lt;BR /&gt;
1000 = A&lt;BR /&gt;
0111 = BCD&lt;BR /&gt;
0110 = BC&lt;BR /&gt;
0101 = BD&lt;BR /&gt;
0100 = B&lt;BR /&gt;
0011 = CD&lt;BR /&gt;
0010 = C&lt;BR /&gt;
0001 = D&lt;BR /&gt;
;

if letters really help to make it clearer, then only at the surface is it different, so format the surface:   &lt;BR /&gt;
Message was edited by: Peter.C</description>
      <pubDate>Mon, 10 Jan 2011 15:07:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-quot-dummy-variable-quot-from-four-different-variables/m-p/60770#M13196</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2011-01-10T15:07:04Z</dc:date>
    </item>
    <item>
      <title>Re: Creating "dummy variable" from four different variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-quot-dummy-variable-quot-from-four-different-variables/m-p/60771#M13197</link>
      <description>hi ... using this ...&lt;BR /&gt;
&lt;BR /&gt;
data _1 _2 _3 _4;&lt;BR /&gt;
id = 10; output _1 _3 _4;&lt;BR /&gt;
id = 20; output _1 _2;&lt;BR /&gt;
id = 30; output _2 _3 _4;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
try this ...&lt;BR /&gt;
&lt;BR /&gt;
data all;&lt;BR /&gt;
length datasource $4;&lt;BR /&gt;
merge _1(in=a) _2(in=b) _3(in=c) _4(in=d);&lt;BR /&gt;
by id;&lt;BR /&gt;
datasource = catt(ifc(a,'A',''),ifc(b,'B',''),ifc(c,'C',''),ifc(d,'D',''));&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
and get ...&lt;BR /&gt;
&lt;BR /&gt;
Obs    datasource    id&lt;BR /&gt;
 1        ACD        10&lt;BR /&gt;
 2        AB         20&lt;BR /&gt;
 3        BCD        30&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: MikeZdeb

Message was edited by: MikeZdeb</description>
      <pubDate>Thu, 13 Jan 2011 21:16:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-quot-dummy-variable-quot-from-four-different-variables/m-p/60771#M13197</guid>
      <dc:creator>MikeZdeb</dc:creator>
      <dc:date>2011-01-13T21:16:23Z</dc:date>
    </item>
  </channel>
</rss>

