<?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 Update NewIDs based on Macro list IDs? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Update-NewIDs-based-on-Macro-list-IDs/m-p/625906#M184546</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a situation.&amp;nbsp;&amp;nbsp; Day 1, I got a dataset 'Day1_macrolist.'&amp;nbsp;&amp;nbsp; Day 2, I got another dataset 'Day2_macrolist.'&amp;nbsp;&amp;nbsp; Day by day, the macrolist will be keep updating from tempID_1 to tempID_6.&amp;nbsp;&amp;nbsp;&amp;nbsp; First, I would like to create a FULL macro list based on daily updates.&amp;nbsp;&amp;nbsp; Then, when I have a TempID in the dataset, I&amp;nbsp;would like to assign the NewID to the TempID based on the macro list ID I have create.&amp;nbsp;&amp;nbsp; Is there an way to approach this?&amp;nbsp; Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data day1_macrolist;
      infile datalines dsd;
  input NewID : $15. TempID_1 : $15.  TempID_2 : $15. TempID_3 : $15. TempID_4 : $15.;
datalines;
1156IL, 8946, 8853, , , 
1487KM, 8956, 7852, , ,
000597, 1596, 4113, , ,
C1156, 4986, 0008, , ,
208, 8MO23, , , ,
21156, 8966, 8852, 5559, , 
;

data day2_macrolist;
      infile datalines dsd;
  input NewID : $15. TempID_1 : $15.  TempID_2 : $15. TempID_3 : $15. TempID_4 : $15. TempID_5 : $15. TempID_6 : $15.;
datalines;
1156IL, 8946, 8853, 7559, , , , 
10235, 0546, 4113, , , , ,
C1156, 4286, 0008, 0009, 4623, 55555, 33333,
200, X1O23, UX689, , , , ,
208, 8MO23, UV689, , , , ,
579, HL2489, GJ627, , , , ,
21156, 8966, 8852, , , , , 
;


data Want;
      infile datalines dsd;
  input TempID : $15.  NewID : $15.;
datalines;
7852, 1156IL, 
4113, 000597, 
55555, C1156,
UX689, 200,
X1O23, 200,
UV689, 208,
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 19 Feb 2020 17:28:47 GMT</pubDate>
    <dc:creator>ybz12003</dc:creator>
    <dc:date>2020-02-19T17:28:47Z</dc:date>
    <item>
      <title>Update NewIDs based on Macro list IDs?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-NewIDs-based-on-Macro-list-IDs/m-p/625906#M184546</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a situation.&amp;nbsp;&amp;nbsp; Day 1, I got a dataset 'Day1_macrolist.'&amp;nbsp;&amp;nbsp; Day 2, I got another dataset 'Day2_macrolist.'&amp;nbsp;&amp;nbsp; Day by day, the macrolist will be keep updating from tempID_1 to tempID_6.&amp;nbsp;&amp;nbsp;&amp;nbsp; First, I would like to create a FULL macro list based on daily updates.&amp;nbsp;&amp;nbsp; Then, when I have a TempID in the dataset, I&amp;nbsp;would like to assign the NewID to the TempID based on the macro list ID I have create.&amp;nbsp;&amp;nbsp; Is there an way to approach this?&amp;nbsp; Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data day1_macrolist;
      infile datalines dsd;
  input NewID : $15. TempID_1 : $15.  TempID_2 : $15. TempID_3 : $15. TempID_4 : $15.;
datalines;
1156IL, 8946, 8853, , , 
1487KM, 8956, 7852, , ,
000597, 1596, 4113, , ,
C1156, 4986, 0008, , ,
208, 8MO23, , , ,
21156, 8966, 8852, 5559, , 
;

data day2_macrolist;
      infile datalines dsd;
  input NewID : $15. TempID_1 : $15.  TempID_2 : $15. TempID_3 : $15. TempID_4 : $15. TempID_5 : $15. TempID_6 : $15.;
datalines;
1156IL, 8946, 8853, 7559, , , , 
10235, 0546, 4113, , , , ,
C1156, 4286, 0008, 0009, 4623, 55555, 33333,
200, X1O23, UX689, , , , ,
208, 8MO23, UV689, , , , ,
579, HL2489, GJ627, , , , ,
21156, 8966, 8852, , , , , 
;


data Want;
      infile datalines dsd;
  input TempID : $15.  NewID : $15.;
datalines;
7852, 1156IL, 
4113, 000597, 
55555, C1156,
UX689, 200,
X1O23, 200,
UV689, 208,
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Feb 2020 17:28:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-NewIDs-based-on-Macro-list-IDs/m-p/625906#M184546</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2020-02-19T17:28:47Z</dc:date>
    </item>
    <item>
      <title>Re: Update NewIDs based on Macro list IDs?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-NewIDs-based-on-Macro-list-IDs/m-p/625976#M184572</link>
      <description>&lt;P&gt;It absolutely not clear how you derived the WANT table:&lt;/P&gt;
&lt;P&gt;First row of want is: TempID=7852 and NewID=1156IL - but&lt;/P&gt;
&lt;P&gt;in DAY1 table the tempID 7852 relate to newID 1487KM&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please explain what is the logic and algorithm to derive what you want.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Feb 2020 20:24:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-NewIDs-based-on-Macro-list-IDs/m-p/625976#M184572</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-02-19T20:24:20Z</dc:date>
    </item>
    <item>
      <title>Re: Update NewIDs based on Macro list IDs?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-NewIDs-based-on-Macro-list-IDs/m-p/626029#M184579</link>
      <description>&lt;P&gt;I apologized that I didn't input the sample data correctly in the morning.&lt;BR /&gt;The TempID_1 - TempID6 should be unique and not duplicate, so does the NewIDs.&lt;BR /&gt;Based on the day1, if the tempID is 7852 then the newID is 1487KM.&lt;/P&gt;
&lt;P&gt;You could change the TempID to 8853 in row 1 of dataset 'Want.'&lt;/P&gt;</description>
      <pubDate>Wed, 19 Feb 2020 23:13:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-NewIDs-based-on-Macro-list-IDs/m-p/626029#M184579</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2020-02-19T23:13:35Z</dc:date>
    </item>
    <item>
      <title>Re: Update NewIDs based on Macro list IDs?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-NewIDs-based-on-Macro-list-IDs/m-p/626045#M184583</link>
      <description>&lt;P&gt;Below should give you some guidance how to implement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* macro definition for maintaining a main macro list
    - for real usage &amp;amp;ouds must be a permanent table and not work
*/
%macro maintain_macroList(
  inds,
  outds=work.macro_list
  );

  %if %sysfunc(exist(&amp;amp;outds, DATA)) ne 1 %then
    %do; 
      /* Create empty table structure */
      data &amp;amp;outds;
        stop;
        length TempID $15 NewID $15;
        call missing(of _all_);
      run;
    %end;

  /* transpose source data to narrow table structure */
  data _tmp_mlist(keep=NewID TempId);
    set &amp;amp;inds;
      array _TempID {*} TempID_:;
    do _i=1 to dim(_TempID) while(not missing(_TempID[_i]));
      TempId=_TempID[_i];
      output;
    end;
  run;
  proc sort data=_tmp_mlist nodupkey;
    by TempID;
  run;

  /* add new tempID's to target table */
  data &amp;amp;outds;
    merge macro_list _tmp_mlist;
    by TempID;
  run;

  /* clean-up: delete intermediary work table */
  proc datasets lib=work nolist nowarn;
    delete _tmp_mlist;
    run;
  quit;
%mend;

/* day 1 macro list maintenance */
data day1_macrolist;
  infile datalines dsd;
  input NewID : $15. TempID_1 : $15.  TempID_2 : $15. TempID_3 : $15. TempID_4 : $15.;
  datalines;
1156IL, 8946, 8853, , , 
1487KM, 8956, 7852, , ,
000597, 1596, 4113, , ,
C1156, 4986, 0008, , ,
208, 8MO23, , , ,
21156, 8966, 8852, 5559, , 
;

%maintain_macroList(day1_macrolist)

/* day 2 macro list maintenance */
data day2_macrolist;
  infile datalines dsd;
  input NewID : $15. TempID_1 : $15.  TempID_2 : $15. TempID_3 : $15. TempID_4 : $15. TempID_5 : $15. TempID_6 : $15.;
  datalines;
1156IL, 8946, 8853, 7559, , , , 
10235, 0546, 4113, , , , ,
C1156, 4286, 0008, 0009, 4623, 55555, 33333,
200, X1O23, UX689, , , , ,
208, 8MO23, UV689, , , , ,
579, HL2489, GJ627, , , , ,
21156, 8966, 8852, , , , , 
;

%maintain_macroList(day2_macrolist)


/* add NewID to source table */
data have;
  infile datalines dsd;
  input TempID : $15.;
  datalines;
7852 
4113
55555
UX689
X1O23
UV689
;

data want;
  if _n_=1 then
    do;
      if 0 then set work.macro_list;
      dcl hash h1(dataset:'work.macro_list');
      h1.defineKey('TempID');
      h1.defineData('NewID');
      h1.defineDone();
    end;
  set have;
  h1.find();
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 20 Feb 2020 03:50:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-NewIDs-based-on-Macro-list-IDs/m-p/626045#M184583</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-02-20T03:50:06Z</dc:date>
    </item>
    <item>
      <title>Re: Update NewIDs based on Macro list IDs?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-NewIDs-based-on-Macro-list-IDs/m-p/626487#M184804</link>
      <description>&lt;P&gt;Thank you so much!&lt;/P&gt;</description>
      <pubDate>Fri, 21 Feb 2020 15:33:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-NewIDs-based-on-Macro-list-IDs/m-p/626487#M184804</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2020-02-21T15:33:46Z</dc:date>
    </item>
  </channel>
</rss>

