<?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: SET on multiple indices in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SET-on-multiple-indices/m-p/15939#M2165</link>
    <description>Hey tangentray,&lt;BR /&gt;
_Null_ is right about the compound index thing. But if you have these 2 indexes already created and maintained and you're not allowed to create extra indexes, then i believe creating compound index of both the variables for just this thing/matching would be a problem for you. &lt;BR /&gt;
If you're doing a lookup on a large dataset ( data B) then i believe format technique of lookup can help( check out paper on SGF 2009 :: Proc Format, a Speedy Alternative to Sort Sort Merge :: &lt;A href="http://support.sas.com/resources/papers/proceedings09/064-2009.pdf" target="_blank"&gt;http://support.sas.com/resources/papers/proceedings09/064-2009.pdf&lt;/A&gt; ) &lt;BR /&gt;
&lt;BR /&gt;
Back when i was learning about the set with Key= option, I wrote something that matches with your multiple index problem ( though not exactly the solution you would want as KEY= Multiple simple indexS is not wht i wrote, but KEY=single simple index with multiple SET statement ). I believe this code would increase the CPU time( if you've read the set ith key= theory you would knw why the increase in time), but the increase is depended on the data and the index variables being sorted/unsorted before they were made index.&lt;BR /&gt;
&lt;BR /&gt;
data master(index=(PartNumber  quantity ));&lt;BR /&gt;
  input PartNumber quantity;&lt;BR /&gt;
datalines;&lt;BR /&gt;
100 10&lt;BR /&gt;
200 20&lt;BR /&gt;
300 30&lt;BR /&gt;
400 40&lt;BR /&gt;
500 50&lt;BR /&gt;
;&lt;BR /&gt;
&lt;BR /&gt;
data description(index=(PartNumber  quantity ));&lt;BR /&gt;
  input PartNumber quantity partdescription $;&lt;BR /&gt;
datalines;&lt;BR /&gt;
400   40       Nuts&lt;BR /&gt;
300   30       Bolts&lt;BR /&gt;
200   10       Screws&lt;BR /&gt;
600   90       Washers&lt;BR /&gt;
500   50       Bashers&lt;BR /&gt;
;&lt;BR /&gt;
&lt;BR /&gt;
data extract;&lt;BR /&gt;
set  description; /* smaller dsn, transaction dsn*/&lt;BR /&gt;
set  master(drop=quantity) key=PartNumber ; /* larger dsn*/&lt;BR /&gt;
&lt;BR /&gt;
length errormessage $200.;&lt;BR /&gt;
drop errormessage;&lt;BR /&gt;
&lt;BR /&gt;
select (_iorc_);&lt;BR /&gt;
    when(%sysrc(_sok)) do;     /* A match was found */&lt;BR /&gt;
           PartNumberX=PartNumber;&lt;BR /&gt;
                   set  master key=quantity ;					&lt;BR /&gt;
                              select (_iorc_);&lt;BR /&gt;
                                  when(%sysrc(_sok)) do;     /* A match was found */&lt;BR /&gt;
                                       if PartNumberx=PartNumber then&lt;BR /&gt;
                                                 output;&lt;BR /&gt;
									else delete;&lt;BR /&gt;
								end;&lt;BR /&gt;
								when (%sysrc(_dsenom)) do; /* No match was found */&lt;BR /&gt;
									_error_ = 0;&lt;BR /&gt;
								end;&lt;BR /&gt;
								otherwise do;&lt;BR /&gt;
									errormessage = iorcmsg();&lt;BR /&gt;
									put "ATTENTION: unknown error condition: "&lt;BR /&gt;
										errormessage;&lt;BR /&gt;
								end;&lt;BR /&gt;
							end;&lt;BR /&gt;
	end;&lt;BR /&gt;
	when (%sysrc(_dsenom)) do; /* No match was found */&lt;BR /&gt;
		_error_ = 0;&lt;BR /&gt;
	end;&lt;BR /&gt;
	otherwise do;&lt;BR /&gt;
		errormessage = iorcmsg();&lt;BR /&gt;
		put "ATTENTION: unknown error condition: "&lt;BR /&gt;
			errormessage;&lt;BR /&gt;
	end;&lt;BR /&gt;
end;&lt;BR /&gt;
run;&lt;BR /&gt;
proc print;run;&lt;BR /&gt;
&lt;BR /&gt;
Thanks!</description>
    <pubDate>Wed, 08 Apr 2009 20:33:33 GMT</pubDate>
    <dc:creator>SushilNayak</dc:creator>
    <dc:date>2009-04-08T20:33:33Z</dc:date>
    <item>
      <title>SET on multiple indices</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-on-multiple-indices/m-p/15937#M2163</link>
      <description>Hi all,&lt;BR /&gt;
&lt;BR /&gt;
I have a problem:&lt;BR /&gt;
I have a sas dataset, say A which has 2 indices defined on say Var1 and Var2.&lt;BR /&gt;
Now I am merging it with dataset B on those 2 variables using the indices, basically my intent is:&lt;BR /&gt;
&lt;B&gt;Data new;&lt;BR /&gt;
merge A (in=a) B(in=b);&lt;BR /&gt;
by Var1 Var2;&lt;BR /&gt;
if b;&lt;BR /&gt;
run;&lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
I am trying like:&lt;BR /&gt;
&lt;B&gt;Data new;&lt;BR /&gt;
set B;&lt;BR /&gt;
set A key=(Var1 Var2);&lt;BR /&gt;
if _IORC_ = 0;&lt;BR /&gt;
run;&lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
The above code gives error, after some research I found that key=&amp;lt; &amp;gt; can only have a single index.&lt;BR /&gt;
&lt;BR /&gt;
The other option would be using the DBKEY but again that works only for database tables and not for sas datasets.&lt;BR /&gt;
&lt;BR /&gt;
Please let me know whether this is possible, that is using SET with multiple indices in the Key= parameter, otherwise what else can be done.&lt;BR /&gt;
&lt;BR /&gt;
Thanks in advance.&lt;BR /&gt;
&lt;BR /&gt;
PS I am not using merge because the indexed approach is more efficient.

Message was edited by: tangentray</description>
      <pubDate>Tue, 07 Apr 2009 09:38:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-on-multiple-indices/m-p/15937#M2163</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-04-07T09:38:41Z</dc:date>
    </item>
    <item>
      <title>Re: SET on multiple indices</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-on-multiple-indices/m-p/15938#M2164</link>
      <description>You have the right idea but the wrong syntax.&lt;BR /&gt;
&lt;BR /&gt;
Create compound index on B.&lt;BR /&gt;
&lt;BR /&gt;
data b(index=(v12=(var1 var2)));&lt;BR /&gt;
&lt;BR /&gt;
then set use&lt;BR /&gt;
&lt;BR /&gt;
set b key=v12/unique;&lt;BR /&gt;
&lt;BR /&gt;
also you will need to set _ERROR_=0 after the set to suppress inplied put _ALL_; produce when _ERROR_=1.</description>
      <pubDate>Tue, 07 Apr 2009 11:41:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-on-multiple-indices/m-p/15938#M2164</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2009-04-07T11:41:27Z</dc:date>
    </item>
    <item>
      <title>Re: SET on multiple indices</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SET-on-multiple-indices/m-p/15939#M2165</link>
      <description>Hey tangentray,&lt;BR /&gt;
_Null_ is right about the compound index thing. But if you have these 2 indexes already created and maintained and you're not allowed to create extra indexes, then i believe creating compound index of both the variables for just this thing/matching would be a problem for you. &lt;BR /&gt;
If you're doing a lookup on a large dataset ( data B) then i believe format technique of lookup can help( check out paper on SGF 2009 :: Proc Format, a Speedy Alternative to Sort Sort Merge :: &lt;A href="http://support.sas.com/resources/papers/proceedings09/064-2009.pdf" target="_blank"&gt;http://support.sas.com/resources/papers/proceedings09/064-2009.pdf&lt;/A&gt; ) &lt;BR /&gt;
&lt;BR /&gt;
Back when i was learning about the set with Key= option, I wrote something that matches with your multiple index problem ( though not exactly the solution you would want as KEY= Multiple simple indexS is not wht i wrote, but KEY=single simple index with multiple SET statement ). I believe this code would increase the CPU time( if you've read the set ith key= theory you would knw why the increase in time), but the increase is depended on the data and the index variables being sorted/unsorted before they were made index.&lt;BR /&gt;
&lt;BR /&gt;
data master(index=(PartNumber  quantity ));&lt;BR /&gt;
  input PartNumber quantity;&lt;BR /&gt;
datalines;&lt;BR /&gt;
100 10&lt;BR /&gt;
200 20&lt;BR /&gt;
300 30&lt;BR /&gt;
400 40&lt;BR /&gt;
500 50&lt;BR /&gt;
;&lt;BR /&gt;
&lt;BR /&gt;
data description(index=(PartNumber  quantity ));&lt;BR /&gt;
  input PartNumber quantity partdescription $;&lt;BR /&gt;
datalines;&lt;BR /&gt;
400   40       Nuts&lt;BR /&gt;
300   30       Bolts&lt;BR /&gt;
200   10       Screws&lt;BR /&gt;
600   90       Washers&lt;BR /&gt;
500   50       Bashers&lt;BR /&gt;
;&lt;BR /&gt;
&lt;BR /&gt;
data extract;&lt;BR /&gt;
set  description; /* smaller dsn, transaction dsn*/&lt;BR /&gt;
set  master(drop=quantity) key=PartNumber ; /* larger dsn*/&lt;BR /&gt;
&lt;BR /&gt;
length errormessage $200.;&lt;BR /&gt;
drop errormessage;&lt;BR /&gt;
&lt;BR /&gt;
select (_iorc_);&lt;BR /&gt;
    when(%sysrc(_sok)) do;     /* A match was found */&lt;BR /&gt;
           PartNumberX=PartNumber;&lt;BR /&gt;
                   set  master key=quantity ;					&lt;BR /&gt;
                              select (_iorc_);&lt;BR /&gt;
                                  when(%sysrc(_sok)) do;     /* A match was found */&lt;BR /&gt;
                                       if PartNumberx=PartNumber then&lt;BR /&gt;
                                                 output;&lt;BR /&gt;
									else delete;&lt;BR /&gt;
								end;&lt;BR /&gt;
								when (%sysrc(_dsenom)) do; /* No match was found */&lt;BR /&gt;
									_error_ = 0;&lt;BR /&gt;
								end;&lt;BR /&gt;
								otherwise do;&lt;BR /&gt;
									errormessage = iorcmsg();&lt;BR /&gt;
									put "ATTENTION: unknown error condition: "&lt;BR /&gt;
										errormessage;&lt;BR /&gt;
								end;&lt;BR /&gt;
							end;&lt;BR /&gt;
	end;&lt;BR /&gt;
	when (%sysrc(_dsenom)) do; /* No match was found */&lt;BR /&gt;
		_error_ = 0;&lt;BR /&gt;
	end;&lt;BR /&gt;
	otherwise do;&lt;BR /&gt;
		errormessage = iorcmsg();&lt;BR /&gt;
		put "ATTENTION: unknown error condition: "&lt;BR /&gt;
			errormessage;&lt;BR /&gt;
	end;&lt;BR /&gt;
end;&lt;BR /&gt;
run;&lt;BR /&gt;
proc print;run;&lt;BR /&gt;
&lt;BR /&gt;
Thanks!</description>
      <pubDate>Wed, 08 Apr 2009 20:33:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SET-on-multiple-indices/m-p/15939#M2165</guid>
      <dc:creator>SushilNayak</dc:creator>
      <dc:date>2009-04-08T20:33:33Z</dc:date>
    </item>
  </channel>
</rss>

