<?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: Multiple set statement with by variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Multiple-set-statement-with-by-variable/m-p/676124#M203823</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13220"&gt;@rajdeep&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;A class="trigger-hovercard" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562" target="_blank" rel="noopener"&gt;KurtBremser&lt;/A&gt;,&lt;/P&gt;
&lt;DIV class="sas-author-username"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sas-author-username"&gt;Thanks a lot for your quick response. I also found the same idea that, it's giving the expected result with Merge, but can you please explain why it's random with multiple SET statement and if suppose we want to make it happen with SET statement then can we achieve the expected output.&lt;/DIV&gt;
&lt;DIV class="sas-author-username"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sas-author-username"&gt;Thanks in advance.&amp;nbsp;&lt;/DIV&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;There is nothing random about it (unless one of the actual datasets is coming from a database that does not provide the observations in the same order each time).&amp;nbsp; When you SET a dataset it reads the next observation from that dataset. If no more observations are available the data step stops.&amp;nbsp; &amp;nbsp;So in each iteration your data step will read one observation from A and then one observation from B.&amp;nbsp; If there are variables in B that were also in A then the values from B will overwrite the values read from A.&amp;nbsp; The number of observations created will be the minimum of the number in A and the number in B.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to match the observations on ACCOUNT_NUMBER then list them both on a MERGE statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to interleave the observations by ACCOUNT_NUMBER then list them both on one SET statement. Then you will get sum of the number of observations. Any variables in A that are not in B will have missing values on the observations that are read from B (and the reverse).&amp;nbsp; If the same ACCOUNT_NUMBER appears in both A and B then both will stay as separate observations with the observations from A appearing before the observations from B.&lt;/P&gt;</description>
    <pubDate>Wed, 12 Aug 2020 12:24:04 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2020-08-12T12:24:04Z</dc:date>
    <item>
      <title>Multiple set statement with by variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-set-statement-with-by-variable/m-p/676009#M203765</link>
      <description>&lt;P&gt;Hi Team,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying a code to execute with the below code, but the ACCOUNT_KEY column values getting plotted randomly from the ACCOUNT_DIM table to the output table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please explain how to freeze ACCOUNT_KEY values against the ACCOUNT_NUMBER column, because every time I run the below step, the ACCOUNT_KEY values are getting changed in the output table for the same Account_numbers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA TEST(KEEP= FTF_IND ACCOUNT_NUMBER ACCOUNT_KEY APP_ID TABLET_ID IMAGE_ID ACQUISITIONTYPE);
SET ACCOUNT_DIM(IN=A KEEP= ACCOUNT_NUMBER ACCOUNT_KEY CHANGE_CURRENT_IND ACCOUNT_REGISTRATION_TYPE_DESC where=(CHANGE_CURRENT_IND='Y'));
SET ACQTYPE(IN=B RENAME=(MAST_ACCOUNT_ID=ACCOUNT_NUMBER));
BY ACCOUNT_NUMBER;
IF A AND B THEN OUTPUT;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Please help if possible.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Aug 2020 21:33:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-set-statement-with-by-variable/m-p/676009#M203765</guid>
      <dc:creator>rajdeep</dc:creator>
      <dc:date>2020-08-11T21:33:21Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple set statement with by variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-set-statement-with-by-variable/m-p/676010#M203766</link>
      <description>&lt;P&gt;You talk about plots, but you don't show us the plot code or the plot output. It would also help if you showed us a portion of this data.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Aug 2020 21:43:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-set-statement-with-by-variable/m-p/676010#M203766</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-08-11T21:43:47Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple set statement with by variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-set-statement-with-by-variable/m-p/676015#M203769</link>
      <description>&lt;P&gt;Really need to provide a small example of data from both sets and what you expect the result of the data step to be for that example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Multiple set statements seldom do what you expect when using them without a LOT of experience.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the &amp;lt;/&amp;gt; icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Aug 2020 22:05:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-set-statement-with-by-variable/m-p/676015#M203769</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-08-11T22:05:06Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple set statement with by variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-set-statement-with-by-variable/m-p/676017#M203771</link>
      <description>&lt;P&gt;The BY and IF statement are doing nothing in that data step (other than possible causing SAS to use an index when accessing the second dataset).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is it you are trying to do?&amp;nbsp; Why not just merge them BY the variable?&lt;/P&gt;</description>
      <pubDate>Tue, 11 Aug 2020 22:09:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-set-statement-with-by-variable/m-p/676017#M203771</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-08-11T22:09:52Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple set statement with by variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-set-statement-with-by-variable/m-p/676038#M203784</link>
      <description>&lt;P&gt;I suspect you are trying to match by account_number.&amp;nbsp; To do that, the two SET statements need to be replaced.&amp;nbsp; This is probably the correct replacement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;merge ACCOUNT_DIM (IN=A KEEP= ACCOUNT_NUMBER ACCOUNT_KEY CHANGE_CURRENT_IND ACCOUNT_REGISTRATION_TYPE_DESC where=(CHANGE_CURRENT_IND='Y'))
      ACQTYPE     (IN=B RENAME=(MAST_ACCOUNT_ID=ACCOUNT_NUMBER));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If that's incorrect, you will need to explain more about what the outcome should be.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Aug 2020 00:15:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-set-statement-with-by-variable/m-p/676038#M203784</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-08-12T00:15:47Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple set statement with by variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-set-statement-with-by-variable/m-p/676086#M203801</link>
      <description>Is the data master/detail ? In other words, for each account_number in ACCOUNT_DIM do you have multiple associated records in ACQTYPE ?</description>
      <pubDate>Wed, 12 Aug 2020 08:04:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-set-statement-with-by-variable/m-p/676086#M203801</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-08-12T08:04:15Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple set statement with by variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-set-statement-with-by-variable/m-p/676100#M203813</link>
      <description>&lt;P&gt;Hi Richard,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please find the sample test data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ACCOUNT_DIM;
INPUT ACCOUNT_KEY 1-7 ACCOUNT_NUMBER $9-14 ACCOUNT_REGISTRATION_TYPE_DESC $ CHANGE_CURRENT_IND $1.;
datalines;
1067347	234057 FTF N
1035020	194500 FTF Y
1067350	234060 FTF Y
1067351	234061 FTF Y
1067352	234062 FTF Y
;
run;

data ACQTYPE;
INPUT ACCOUNT_NUMBER $1-6 ACQUISITIONTYPE $7-11 FTF_IND $13-16 APP_ID 18-23  TABLET_ID $25-26 IMAGE_ID $28-29;
datalines;
234061 FTFT FTF  268074    
234062 FTFT FTF  268074    
111111 NFTF NFTF 268074    
111123 NFTF NFTF 268074    
111134 NFTF NFTF 268074    
;
run;
proc sort data=ACQTYPE;
by account_number;
run;


DATA TEST(KEEP= FTF_IND ACCOUNT_NUMBER ACCOUNT_KEY APP_ID TABLET_ID IMAGE_ID ACQUISITIONTYPE);
set ACCOUNT_DIM(IN=A KEEP= ACCOUNT_NUMBER ACCOUNT_KEY CHANGE_CURRENT_IND ACCOUNT_REGISTRATION_TYPE_DESC where=(CHANGE_CURRENT_IND='Y')) ;
 set ACQTYPE(IN=B );
BY ACCOUNT_NUMBER;
IF A AND B THEN OUTPUT;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I just want the&amp;nbsp;1067351 &amp;amp; 1067352 ACCOUNT_KEYs should be mapped against the&amp;nbsp;234061 &amp;amp;&amp;nbsp;234062 ACCOUNT_NUMBERs in the output dataset i.e TEST. If you try executing again and again you can see the random ACCOUNT_KEYs is coming ahead of&amp;nbsp;234061 &amp;amp;&amp;nbsp;234062 ACCOUNT_NUMBERS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for your quick reply. please let me know if there's any disconnect.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P data-unlink="true"&gt;@&lt;/P&gt;
&lt;DIV class="sas-author-username"&gt;&lt;A class="trigger-hovercard" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892" target="_blank"&gt;PaigeMiller&lt;/A&gt;&amp;nbsp;extremely sorry for the plot word confusion, I meant mapping actually.&lt;/DIV&gt;
&lt;DIV class="sas-author-username"&gt;@
&lt;DIV class="sas-author-username"&gt;&lt;A class="trigger-hovercard" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884" target="_blank"&gt;ballardw&lt;/A&gt;&amp;nbsp;Thanks for your reply. you are correct, experience matters a lot. I am still learning actually.&lt;/DIV&gt;
&lt;DIV class="sas-author-username"&gt;
&lt;DIV class="sas-author-username"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sas-author-username"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sas-author-username"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Wed, 12 Aug 2020 09:36:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-set-statement-with-by-variable/m-p/676100#M203813</guid>
      <dc:creator>rajdeep</dc:creator>
      <dc:date>2020-08-12T09:36:37Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple set statement with by variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-set-statement-with-by-variable/m-p/676114#M203818</link>
      <description>&lt;P&gt;So it should be a simple MERGE by account_number?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ACCOUNT_DIM;
input
  ACCOUNT_KEY 1-7
  ACCOUNT_NUMBER $9-14
  ACCOUNT_REGISTRATION_TYPE_DESC $
  CHANGE_CURRENT_IND $1.
;
datalines;
1067347 234057 FTF N
1035020 194500 FTF Y
1067350 234060 FTF Y
1067351 234061 FTF Y
1067352 234062 FTF Y
;

data ACQTYPE;
input
  ACCOUNT_NUMBER $1-6
  ACQUISITIONTYPE $7-11
  FTF_IND $13-16
  APP_ID 18-23
  TABLET_ID $25-26
  IMAGE_ID $28-29
;
datalines;
234061 FTFT FTF  268074    
234062 FTFT FTF  268074    
111111 NFTF NFTF 268074    
111123 NFTF NFTF 268074    
111134 NFTF NFTF 268074    
;

proc sort data=ACQTYPE;
by account_number;
run;

data test (
  keep=
    FTF_IND ACCOUNT_NUMBER ACCOUNT_KEY APP_ID
    TABLET_ID IMAGE_ID ACQUISITIONTYPE
);
merge
  ACCOUNT_DIM (
    in=a
    keep=
      ACCOUNT_NUMBER ACCOUNT_KEY CHANGE_CURRENT_IND
      ACCOUNT_REGISTRATION_TYPE_DESC
    where=(CHANGE_CURRENT_IND='Y')
  )
  ACQTYPE (in=b)
;
by account_number;
if a and b;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 Aug 2020 11:06:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-set-statement-with-by-variable/m-p/676114#M203818</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-08-12T11:06:44Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple set statement with by variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-set-statement-with-by-variable/m-p/676121#M203820</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;A class="trigger-hovercard" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562" target="_blank"&gt;KurtBremser&lt;/A&gt;,&lt;/P&gt;
&lt;DIV class="sas-author-username"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sas-author-username"&gt;Thanks a lot for your quick response. I also found the same idea that, it's giving the expected result with Merge, but can you please explain why it's random with multiple SET statement and if suppose we want to make it happen with SET statement then can we achieve the expected output.&lt;/DIV&gt;
&lt;DIV class="sas-author-username"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sas-author-username"&gt;Thanks in advance.&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Wed, 12 Aug 2020 12:10:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-set-statement-with-by-variable/m-p/676121#M203820</guid>
      <dc:creator>rajdeep</dc:creator>
      <dc:date>2020-08-12T12:10:05Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple set statement with by variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-set-statement-with-by-variable/m-p/676124#M203823</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13220"&gt;@rajdeep&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;A class="trigger-hovercard" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562" target="_blank" rel="noopener"&gt;KurtBremser&lt;/A&gt;,&lt;/P&gt;
&lt;DIV class="sas-author-username"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sas-author-username"&gt;Thanks a lot for your quick response. I also found the same idea that, it's giving the expected result with Merge, but can you please explain why it's random with multiple SET statement and if suppose we want to make it happen with SET statement then can we achieve the expected output.&lt;/DIV&gt;
&lt;DIV class="sas-author-username"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sas-author-username"&gt;Thanks in advance.&amp;nbsp;&lt;/DIV&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;There is nothing random about it (unless one of the actual datasets is coming from a database that does not provide the observations in the same order each time).&amp;nbsp; When you SET a dataset it reads the next observation from that dataset. If no more observations are available the data step stops.&amp;nbsp; &amp;nbsp;So in each iteration your data step will read one observation from A and then one observation from B.&amp;nbsp; If there are variables in B that were also in A then the values from B will overwrite the values read from A.&amp;nbsp; The number of observations created will be the minimum of the number in A and the number in B.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to match the observations on ACCOUNT_NUMBER then list them both on a MERGE statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to interleave the observations by ACCOUNT_NUMBER then list them both on one SET statement. Then you will get sum of the number of observations. Any variables in A that are not in B will have missing values on the observations that are read from B (and the reverse).&amp;nbsp; If the same ACCOUNT_NUMBER appears in both A and B then both will stay as separate observations with the observations from A appearing before the observations from B.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Aug 2020 12:24:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-set-statement-with-by-variable/m-p/676124#M203823</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-08-12T12:24:04Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple set statement with by variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-set-statement-with-by-variable/m-p/676135#M203824</link>
      <description>&lt;P&gt;What you wanted is a merge, so you use that statement. SET has other uses, as you could see and as was explained by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Aug 2020 12:33:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-set-statement-with-by-variable/m-p/676135#M203824</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-08-12T12:33:23Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple set statement with by variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-set-statement-with-by-variable/m-p/676186#M203849</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13220"&gt;@rajdeep&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;A class="trigger-hovercard" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562" target="_blank" rel="noopener"&gt;KurtBremser&lt;/A&gt;,&lt;/P&gt;
&lt;DIV class="sas-author-username"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sas-author-username"&gt;Thanks a lot for your quick response. I also found the same idea that, it's giving the expected result with Merge, but can you please explain why it's random with multiple SET statement and if suppose we want to make it happen with SET statement then can we achieve the expected output.&lt;/DIV&gt;
&lt;DIV class="sas-author-username"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sas-author-username"&gt;Thanks in advance.&amp;nbsp;&lt;/DIV&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Not random just complicated. As I said, multiple set statements without experience are difficult to work with. If you do not control the order of data then it can get more unpredictable.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Aug 2020 14:47:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-set-statement-with-by-variable/m-p/676186#M203849</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-08-12T14:47:07Z</dc:date>
    </item>
  </channel>
</rss>

