<?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: SAS Merge problem in Developers</title>
    <link>https://communities.sas.com/t5/Developers/SAS-Merge-problem/m-p/5362#M2079</link>
    <description>Hi:&lt;BR /&gt;
  It occurs to me that this is very similar to another question on the forum:&lt;BR /&gt;
&lt;A href="http://support.sas.com/forums/thread.jspa?threadID=2097&amp;amp;tstart=0" target="_blank"&gt;http://support.sas.com/forums/thread.jspa?threadID=2097&amp;amp;tstart=0&lt;/A&gt; &lt;BR /&gt;
&lt;BR /&gt;
That person wanted to count people who appeared in a group and you want to do essentially the same thing.&lt;BR /&gt;
 &lt;BR /&gt;
Here's a PROC TABULATE solution that uses a SAS format to do the lookup so you don't have to code it in a MERGE. I coded the format the way I did because it seems that column A is tied to the value in column B and rather than loading 2 formats, it was easier to just load 1 format.&lt;BR /&gt;
&lt;BR /&gt;
For more help understanding what this program is doing, you might consider reading the PROC TABULATE and PROC FORMAT documentation or contacting Tech Support for help with your particular set of data and output needs. For example, do you need an output table or an output report??? In any case, the Stored Process forum is not the right spot to post questions like this. Beginning syntax or usage questions are most appropriate for Tech Support.&lt;BR /&gt;
&lt;BR /&gt;
cynthia&lt;BR /&gt;
[pre]&lt;BR /&gt;
    &lt;BR /&gt;
proc format;&lt;BR /&gt;
  value lookup&lt;BR /&gt;
  1000 = '20 1000'&lt;BR /&gt;
  1001 = '20 1001'&lt;BR /&gt;
  1002 = '20 1002'&lt;BR /&gt;
  1003 = '21 1003'&lt;BR /&gt;
  1004 = '21 1004'&lt;BR /&gt;
  1005 = '21 1005'&lt;BR /&gt;
  1006 = '22 1006'&lt;BR /&gt;
  1007 = '22 1007'&lt;BR /&gt;
  1008 = '23 1008'&lt;BR /&gt;
  1009 = '23 1009'&lt;BR /&gt;
  1010 = '23 1010';&lt;BR /&gt;
run;&lt;BR /&gt;
    &lt;BR /&gt;
data consumer;&lt;BR /&gt;
  infile datalines;&lt;BR /&gt;
  input CID $ a b;&lt;BR /&gt;
return;&lt;BR /&gt;
datalines;&lt;BR /&gt;
abc 20 1001&lt;BR /&gt;
abc 20 1002&lt;BR /&gt;
abc 21 1005&lt;BR /&gt;
abc 22 1007&lt;BR /&gt;
xyz 20 1002&lt;BR /&gt;
xyz 21 1004&lt;BR /&gt;
xyz 22 1006&lt;BR /&gt;
xyz 23 1010&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
    &lt;BR /&gt;
ods listing;&lt;BR /&gt;
ods html file='c:\temp\tabexamp.html';&lt;BR /&gt;
  &lt;BR /&gt;
** PROC TABULATE;&lt;BR /&gt;
  &lt;BR /&gt;
options missing=0 nodate nonumber;&lt;BR /&gt;
  &lt;BR /&gt;
proc tabulate data=consumer f=comma8.&lt;BR /&gt;
          formchar='|----|+|--- '&lt;BR /&gt;
          out=work.tabout;&lt;BR /&gt;
  title "Using PROC TABULATE";&lt;BR /&gt;
  class cid;&lt;BR /&gt;
  class b /preloadfmt;&lt;BR /&gt;
  table cid* b, n / printmiss;&lt;BR /&gt;
  label b = 'A and B';&lt;BR /&gt;
  keylabel n = 'Total Category';&lt;BR /&gt;
  format b lookup.;&lt;BR /&gt;
run;&lt;BR /&gt;
    &lt;BR /&gt;
** show output data created by tabulate;&lt;BR /&gt;
proc print data=tabout;&lt;BR /&gt;
  title 'proc print of data created by tabulate';&lt;BR /&gt;
  title2 'column "B" uses LOOKUP format';&lt;BR /&gt;
  var cid b n;&lt;BR /&gt;
run; &lt;BR /&gt;
    &lt;BR /&gt;
ods html close;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
and the TABULATE output in the LISTING window would look like this:&lt;BR /&gt;
[pre]&lt;BR /&gt;
Using PROC TABULATE&lt;BR /&gt;
&lt;BR /&gt;
-----------------------------&lt;BR /&gt;
|                  | Total  |&lt;BR /&gt;
|                  |Category|&lt;BR /&gt;
|------------------+--------|&lt;BR /&gt;
|CID     |A and B  |        |&lt;BR /&gt;
|--------+---------|        |&lt;BR /&gt;
|abc     |20 1000  |       0|&lt;BR /&gt;
|        |---------+--------|&lt;BR /&gt;
|        |20 1001  |       1|&lt;BR /&gt;
|        |---------+--------|&lt;BR /&gt;
|        |20 1002  |       1|&lt;BR /&gt;
|        |---------+--------|&lt;BR /&gt;
|        |21 1003  |       0|&lt;BR /&gt;
|        |---------+--------|&lt;BR /&gt;
|        |21 1004  |       0|&lt;BR /&gt;
|        |---------+--------|&lt;BR /&gt;
|        |21 1005  |       1|&lt;BR /&gt;
|        |---------+--------|&lt;BR /&gt;
|        |22 1006  |       0|&lt;BR /&gt;
|        |---------+--------|&lt;BR /&gt;
|        |22 1007  |       1|&lt;BR /&gt;
|        |---------+--------|&lt;BR /&gt;
|        |23 1008  |       0|&lt;BR /&gt;
|        |---------+--------|&lt;BR /&gt;
|        |23 1009  |       0|&lt;BR /&gt;
|        |---------+--------|&lt;BR /&gt;
|        |23 1010  |       0|&lt;BR /&gt;
|--------+---------+--------|&lt;BR /&gt;
|xyz     |20 1000  |       0|&lt;BR /&gt;
|        |---------+--------|&lt;BR /&gt;
|        |20 1001  |       0|&lt;BR /&gt;
|        |---------+--------|&lt;BR /&gt;
|        |20 1002  |       1|&lt;BR /&gt;
|        |---------+--------|&lt;BR /&gt;
|        |21 1003  |       0|&lt;BR /&gt;
|        |---------+--------|&lt;BR /&gt;
|        |21 1004  |       1|&lt;BR /&gt;
|        |---------+--------|&lt;BR /&gt;
|        |21 1005  |       0|&lt;BR /&gt;
|        |---------+--------|&lt;BR /&gt;
|        |22 1006  |       1|&lt;BR /&gt;
|        |---------+--------|&lt;BR /&gt;
|        |22 1007  |       0|&lt;BR /&gt;
|        |---------+--------|&lt;BR /&gt;
|        |23 1008  |       0|&lt;BR /&gt;
|        |---------+--------|&lt;BR /&gt;
|        |23 1009  |       0|&lt;BR /&gt;
|        |---------+--------|&lt;BR /&gt;
|        |23 1010  |       1|&lt;BR /&gt;
-----------------------------&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
[/pre]</description>
    <pubDate>Tue, 06 Nov 2007 17:40:31 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2007-11-06T17:40:31Z</dc:date>
    <item>
      <title>SAS Merge problem</title>
      <link>https://communities.sas.com/t5/Developers/SAS-Merge-problem/m-p/5360#M2077</link>
      <description>Hi All,&lt;BR /&gt;
&lt;BR /&gt;
I have just started programming in SAS and I am stuck at a point where I am not able to see a solution. The problem may be very simple for some and my apologies.&lt;BR /&gt;
&lt;BR /&gt;
I have following data -&lt;BR /&gt;
&lt;BR /&gt;
File lookup:&lt;BR /&gt;
A    B&lt;BR /&gt;
20   1000&lt;BR /&gt;
20   1001&lt;BR /&gt;
20   1002&lt;BR /&gt;
21   1003&lt;BR /&gt;
21   1004&lt;BR /&gt;
21   1005&lt;BR /&gt;
22   1006&lt;BR /&gt;
22   1007&lt;BR /&gt;
23   1008&lt;BR /&gt;
23   1009&lt;BR /&gt;
23   1010&lt;BR /&gt;
&lt;BR /&gt;
File Consumer Data:&lt;BR /&gt;
CID   A     B&lt;BR /&gt;
abc   20    1001&lt;BR /&gt;
abc   20    1002&lt;BR /&gt;
abc   21    1005&lt;BR /&gt;
abc   22    1007&lt;BR /&gt;
xyz   20    1002&lt;BR /&gt;
xyz   21    1004&lt;BR /&gt;
xyz   22    1006&lt;BR /&gt;
xyz   23    1010&lt;BR /&gt;
&lt;BR /&gt;
The out file should have:&lt;BR /&gt;
&lt;BR /&gt;
ID    	A      B   Flag&lt;BR /&gt;
abc       20   1000  0 	&lt;BR /&gt;
abc       20   1001  1 &lt;BR /&gt;
abc       20   1002  1 &lt;BR /&gt;
abc	21   1003  0 &lt;BR /&gt;
abc	21   1004  0&lt;BR /&gt;
abc	21   1005  1&lt;BR /&gt;
abc       22   1006  0 &lt;BR /&gt;
abc	22   1007  1&lt;BR /&gt;
abc	23   1008  0 &lt;BR /&gt;
abc	23   1009  0 &lt;BR /&gt;
abc	23   1010  0&lt;BR /&gt;
&lt;BR /&gt;
xyz       20   1000  0 	&lt;BR /&gt;
xyz       20   1001  0 &lt;BR /&gt;
xyz	20   1002  1 &lt;BR /&gt;
xyz	21   1003  0 &lt;BR /&gt;
xyz	21   1004  1&lt;BR /&gt;
xyz	21   1005  0&lt;BR /&gt;
xyz       22   1006  1 &lt;BR /&gt;
xyz	22   1007  0&lt;BR /&gt;
xyz	23   1008  0 &lt;BR /&gt;
xyz	23   1009  0 &lt;BR /&gt;
xyz	23   1010  1&lt;BR /&gt;
&lt;BR /&gt;
So basically, look up would be used like a reference library to merge on for each customer id. And binary 0 or 1 is set against each observation based on the tuple A B chosen by customer.&lt;BR /&gt;
&lt;BR /&gt;
I can very easily think of solving it in JAVA/C++ but I want to learn a solution in SAS.&lt;BR /&gt;
&lt;BR /&gt;
Thanks for all the suggestions and help!</description>
      <pubDate>Fri, 02 Nov 2007 16:37:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/SAS-Merge-problem/m-p/5360#M2077</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2007-11-02T16:37:00Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Merge problem</title>
      <link>https://communities.sas.com/t5/Developers/SAS-Merge-problem/m-p/5361#M2078</link>
      <description>Hi:&lt;BR /&gt;
  This question is not directly related to SAS Stored Processes. For help with how to combine or manipulate data, your best bet is to read the documentation on joining SAS data sets or to contact Tech Support for help on this particular problem. &lt;BR /&gt;
&lt;BR /&gt;
Some papers on the subject are:&lt;BR /&gt;
&lt;A href="http://www2.sas.com/proceedings/sugi28/097-28.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi28/097-28.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://www2.sas.com/proceedings/sugi30/061-30.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi30/061-30.pdf&lt;/A&gt;&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Fri, 02 Nov 2007 17:50:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/SAS-Merge-problem/m-p/5361#M2078</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2007-11-02T17:50:43Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Merge problem</title>
      <link>https://communities.sas.com/t5/Developers/SAS-Merge-problem/m-p/5362#M2079</link>
      <description>Hi:&lt;BR /&gt;
  It occurs to me that this is very similar to another question on the forum:&lt;BR /&gt;
&lt;A href="http://support.sas.com/forums/thread.jspa?threadID=2097&amp;amp;tstart=0" target="_blank"&gt;http://support.sas.com/forums/thread.jspa?threadID=2097&amp;amp;tstart=0&lt;/A&gt; &lt;BR /&gt;
&lt;BR /&gt;
That person wanted to count people who appeared in a group and you want to do essentially the same thing.&lt;BR /&gt;
 &lt;BR /&gt;
Here's a PROC TABULATE solution that uses a SAS format to do the lookup so you don't have to code it in a MERGE. I coded the format the way I did because it seems that column A is tied to the value in column B and rather than loading 2 formats, it was easier to just load 1 format.&lt;BR /&gt;
&lt;BR /&gt;
For more help understanding what this program is doing, you might consider reading the PROC TABULATE and PROC FORMAT documentation or contacting Tech Support for help with your particular set of data and output needs. For example, do you need an output table or an output report??? In any case, the Stored Process forum is not the right spot to post questions like this. Beginning syntax or usage questions are most appropriate for Tech Support.&lt;BR /&gt;
&lt;BR /&gt;
cynthia&lt;BR /&gt;
[pre]&lt;BR /&gt;
    &lt;BR /&gt;
proc format;&lt;BR /&gt;
  value lookup&lt;BR /&gt;
  1000 = '20 1000'&lt;BR /&gt;
  1001 = '20 1001'&lt;BR /&gt;
  1002 = '20 1002'&lt;BR /&gt;
  1003 = '21 1003'&lt;BR /&gt;
  1004 = '21 1004'&lt;BR /&gt;
  1005 = '21 1005'&lt;BR /&gt;
  1006 = '22 1006'&lt;BR /&gt;
  1007 = '22 1007'&lt;BR /&gt;
  1008 = '23 1008'&lt;BR /&gt;
  1009 = '23 1009'&lt;BR /&gt;
  1010 = '23 1010';&lt;BR /&gt;
run;&lt;BR /&gt;
    &lt;BR /&gt;
data consumer;&lt;BR /&gt;
  infile datalines;&lt;BR /&gt;
  input CID $ a b;&lt;BR /&gt;
return;&lt;BR /&gt;
datalines;&lt;BR /&gt;
abc 20 1001&lt;BR /&gt;
abc 20 1002&lt;BR /&gt;
abc 21 1005&lt;BR /&gt;
abc 22 1007&lt;BR /&gt;
xyz 20 1002&lt;BR /&gt;
xyz 21 1004&lt;BR /&gt;
xyz 22 1006&lt;BR /&gt;
xyz 23 1010&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
    &lt;BR /&gt;
ods listing;&lt;BR /&gt;
ods html file='c:\temp\tabexamp.html';&lt;BR /&gt;
  &lt;BR /&gt;
** PROC TABULATE;&lt;BR /&gt;
  &lt;BR /&gt;
options missing=0 nodate nonumber;&lt;BR /&gt;
  &lt;BR /&gt;
proc tabulate data=consumer f=comma8.&lt;BR /&gt;
          formchar='|----|+|--- '&lt;BR /&gt;
          out=work.tabout;&lt;BR /&gt;
  title "Using PROC TABULATE";&lt;BR /&gt;
  class cid;&lt;BR /&gt;
  class b /preloadfmt;&lt;BR /&gt;
  table cid* b, n / printmiss;&lt;BR /&gt;
  label b = 'A and B';&lt;BR /&gt;
  keylabel n = 'Total Category';&lt;BR /&gt;
  format b lookup.;&lt;BR /&gt;
run;&lt;BR /&gt;
    &lt;BR /&gt;
** show output data created by tabulate;&lt;BR /&gt;
proc print data=tabout;&lt;BR /&gt;
  title 'proc print of data created by tabulate';&lt;BR /&gt;
  title2 'column "B" uses LOOKUP format';&lt;BR /&gt;
  var cid b n;&lt;BR /&gt;
run; &lt;BR /&gt;
    &lt;BR /&gt;
ods html close;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
and the TABULATE output in the LISTING window would look like this:&lt;BR /&gt;
[pre]&lt;BR /&gt;
Using PROC TABULATE&lt;BR /&gt;
&lt;BR /&gt;
-----------------------------&lt;BR /&gt;
|                  | Total  |&lt;BR /&gt;
|                  |Category|&lt;BR /&gt;
|------------------+--------|&lt;BR /&gt;
|CID     |A and B  |        |&lt;BR /&gt;
|--------+---------|        |&lt;BR /&gt;
|abc     |20 1000  |       0|&lt;BR /&gt;
|        |---------+--------|&lt;BR /&gt;
|        |20 1001  |       1|&lt;BR /&gt;
|        |---------+--------|&lt;BR /&gt;
|        |20 1002  |       1|&lt;BR /&gt;
|        |---------+--------|&lt;BR /&gt;
|        |21 1003  |       0|&lt;BR /&gt;
|        |---------+--------|&lt;BR /&gt;
|        |21 1004  |       0|&lt;BR /&gt;
|        |---------+--------|&lt;BR /&gt;
|        |21 1005  |       1|&lt;BR /&gt;
|        |---------+--------|&lt;BR /&gt;
|        |22 1006  |       0|&lt;BR /&gt;
|        |---------+--------|&lt;BR /&gt;
|        |22 1007  |       1|&lt;BR /&gt;
|        |---------+--------|&lt;BR /&gt;
|        |23 1008  |       0|&lt;BR /&gt;
|        |---------+--------|&lt;BR /&gt;
|        |23 1009  |       0|&lt;BR /&gt;
|        |---------+--------|&lt;BR /&gt;
|        |23 1010  |       0|&lt;BR /&gt;
|--------+---------+--------|&lt;BR /&gt;
|xyz     |20 1000  |       0|&lt;BR /&gt;
|        |---------+--------|&lt;BR /&gt;
|        |20 1001  |       0|&lt;BR /&gt;
|        |---------+--------|&lt;BR /&gt;
|        |20 1002  |       1|&lt;BR /&gt;
|        |---------+--------|&lt;BR /&gt;
|        |21 1003  |       0|&lt;BR /&gt;
|        |---------+--------|&lt;BR /&gt;
|        |21 1004  |       1|&lt;BR /&gt;
|        |---------+--------|&lt;BR /&gt;
|        |21 1005  |       0|&lt;BR /&gt;
|        |---------+--------|&lt;BR /&gt;
|        |22 1006  |       1|&lt;BR /&gt;
|        |---------+--------|&lt;BR /&gt;
|        |22 1007  |       0|&lt;BR /&gt;
|        |---------+--------|&lt;BR /&gt;
|        |23 1008  |       0|&lt;BR /&gt;
|        |---------+--------|&lt;BR /&gt;
|        |23 1009  |       0|&lt;BR /&gt;
|        |---------+--------|&lt;BR /&gt;
|        |23 1010  |       1|&lt;BR /&gt;
-----------------------------&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
[/pre]</description>
      <pubDate>Tue, 06 Nov 2007 17:40:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/SAS-Merge-problem/m-p/5362#M2079</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2007-11-06T17:40:31Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Merge problem</title>
      <link>https://communities.sas.com/t5/Developers/SAS-Merge-problem/m-p/5363#M2080</link>
      <description>Thanks a lot for that solution Cynthia!</description>
      <pubDate>Tue, 06 Nov 2007 18:24:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/SAS-Merge-problem/m-p/5363#M2080</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2007-11-06T18:24:17Z</dc:date>
    </item>
  </channel>
</rss>

