<?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: Mashing datasets with different varaibles in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Mashing-datasets-with-different-varaibles/m-p/523675#M142293</link>
    <description>&lt;P&gt;The issue you are describing would actually not cause any trouble for the code you posted.&lt;/P&gt;
&lt;P&gt;Here is an example that proves it.&lt;/P&gt;
&lt;PRE&gt;135   data base (keep=dx1-dx10) add (keep=dx1-dx5 );
136    array dx (10) $10 ;
137   run;

NOTE: The data set WORK.BASE has 1 observations and 10 variables.
NOTE: The data set WORK.ADD has 1 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.02 seconds
      cpu time            0.03 seconds


138
139   proc append base=base data=add ;
140   run;

NOTE: Appending WORK.ADD to WORK.BASE.
WARNING: Variable dx6 was not found on DATA file.
WARNING: Variable dx7 was not found on DATA file.
WARNING: Variable dx8 was not found on DATA file.
WARNING: Variable dx9 was not found on DATA file.
WARNING: Variable dx10 was not found on DATA file.
NOTE: There were 1 observations read from the data set WORK.ADD.
NOTE: 1 observations added.
NOTE: The data set WORK.BASE has 2 observations and 10 variables.
&lt;/PRE&gt;
&lt;P&gt;If you want to get rid of the WARNING messages you could just add the extra variables when you make the copy of the data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro bta(fy);
libname bta "/bta/tdata/fy&amp;amp;fy.";

data tdata ;
  set bta.teddy ;
  if tflflag = "U" and place="26" then delete;
  array dx (25) ;
run;

** Remove any duplicate records **;
proc sort data=tdata nodupkey;
  by _all_;
run;

** Append to one data set **;
proc append data = tdata base = crc.tdata;
run;

** Clean up **;
proc delete data=tdata;
run;

%mend bta;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 27 Dec 2018 17:42:50 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2018-12-27T17:42:50Z</dc:date>
    <item>
      <title>Mashing datasets with different varaibles</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Mashing-datasets-with-different-varaibles/m-p/523643#M142277</link>
      <description>&lt;P&gt;Hello Everybody!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have one dataset that has diagnoses 1 thru 8 (DX1-DX8) and a bunch of others that have DX1-DX25. I'm trying to use one macro to process all these datasets but can't quite figure out how to do it. Instead I've duplicated the macro so that one will process the one file and the other processes the others, then use Proc Append to mash them together. Just wondering if there is a more elegant way to do this using one macro?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Brian&lt;/P&gt;</description>
      <pubDate>Thu, 27 Dec 2018 15:13:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Mashing-datasets-with-different-varaibles/m-p/523643#M142277</guid>
      <dc:creator>BTAinRVA</dc:creator>
      <dc:date>2018-12-27T15:13:48Z</dc:date>
    </item>
    <item>
      <title>Re: Mashing datasets with different varaibles</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Mashing-datasets-with-different-varaibles/m-p/523646#M142278</link>
      <description>&lt;P&gt;Hi Brian,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The ultimate answer will probably depend on what you mean by "processing". But when assuming you mean you want to do stuff to a dataset and not be hindered by some missing variables then the following code would first add them (and obviously assign them missing values). It does assume (again) that there is a known datasets that has DX1-DX25:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.processthisone / view=work.processthisone;
   if 0 the set datasetwithallvars;
   set nextdataset;
run;

/* Go and do your processing on work.processthisone */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The code uses a view to avoid having to go through all data just to change the dataset descriptor. The "if 0" construct avoids reading the data from the template dataset at run-time while the variable definitions are imported at compile-time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps,&lt;/P&gt;
&lt;P&gt;-- Jan.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Dec 2018 15:25:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Mashing-datasets-with-different-varaibles/m-p/523646#M142278</guid>
      <dc:creator>jklaverstijn</dc:creator>
      <dc:date>2018-12-27T15:25:56Z</dc:date>
    </item>
    <item>
      <title>Re: Mashing datasets with different varaibles</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Mashing-datasets-with-different-varaibles/m-p/523649#M142279</link>
      <description>&lt;P&gt;It is probably possible to write SAS code (without macro logic at all) that could process both.&amp;nbsp; For example this code would work.&amp;nbsp; It would just end up making extra empty variables for the source data that started with only 8.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set have ;
  array dx dx1-dx25;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could just tell your macro how many variables to process.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro my_marcro(dsn=,ndx=);
....
array dx (&amp;amp;ndx) $10 ;
....
%mend ;
%my_macro(dsn=outpatient,ndx=8);
%my_macro(dsn=inpatient,ndx=25);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you could let your macro figure out how many DX variable you have.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents noprint data=&amp;amp;dsn out=contents ; run;
proc sql noprint;
  select name into :dx_list separated by ' '
  from contents where upcase(name) like 'DX%' 
  ;
quit;
....
array dx &amp;amp;dx_list ;
....&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 Dec 2018 15:33:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Mashing-datasets-with-different-varaibles/m-p/523649#M142279</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-12-27T15:33:07Z</dc:date>
    </item>
    <item>
      <title>Re: Mashing datasets with different varaibles</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Mashing-datasets-with-different-varaibles/m-p/523656#M142283</link>
      <description>&lt;P&gt;Jan,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for the illuminating reply! I learned something today.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unfortunately I'm not sure it would work in my case. The macro opens up datasets stored in different directories, processes them, then appends them, kind of like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro bta(fy);&lt;BR /&gt;&amp;nbsp;libname bta "/bta/tdata/fy&amp;amp;fy.";&lt;/P&gt;
&lt;P&gt;&amp;nbsp;data tdata&amp;amp;fy.;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;set bta.teddy ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;if tflflag = "U" and place="26" then delete;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;** Remove any duplicate records **;&lt;BR /&gt;&amp;nbsp;proc sort data=tdata&amp;amp;fy. nodupkey;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; by _all_;&lt;BR /&gt;&amp;nbsp;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;** Append to one data set **;&lt;BR /&gt;&amp;nbsp;proc append data = tdata&amp;amp;fy. base = crc.tdata;&lt;BR /&gt;&amp;nbsp;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;** Clean up **;&lt;BR /&gt;&amp;nbsp;proc datasets memtype=data lib=work nolist;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; delete tdata&amp;amp;fy.;&lt;BR /&gt;&amp;nbsp;quit;&lt;BR /&gt;&amp;nbsp;run;&lt;/P&gt;
&lt;P&gt;%mend bta;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;%bta(03);&lt;BR /&gt;%bta(04);&lt;BR /&gt;%bta(05);&lt;BR /&gt;%bta(06);&lt;BR /&gt;%bta(07);&lt;BR /&gt;%bta(08);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The 03 dataset has DX1-DX8 while the others have DX1-DX25.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Dec 2018 16:06:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Mashing-datasets-with-different-varaibles/m-p/523656#M142283</guid>
      <dc:creator>BTAinRVA</dc:creator>
      <dc:date>2018-12-27T16:06:51Z</dc:date>
    </item>
    <item>
      <title>Re: Mashing datasets with different varaibles</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Mashing-datasets-with-different-varaibles/m-p/523675#M142293</link>
      <description>&lt;P&gt;The issue you are describing would actually not cause any trouble for the code you posted.&lt;/P&gt;
&lt;P&gt;Here is an example that proves it.&lt;/P&gt;
&lt;PRE&gt;135   data base (keep=dx1-dx10) add (keep=dx1-dx5 );
136    array dx (10) $10 ;
137   run;

NOTE: The data set WORK.BASE has 1 observations and 10 variables.
NOTE: The data set WORK.ADD has 1 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.02 seconds
      cpu time            0.03 seconds


138
139   proc append base=base data=add ;
140   run;

NOTE: Appending WORK.ADD to WORK.BASE.
WARNING: Variable dx6 was not found on DATA file.
WARNING: Variable dx7 was not found on DATA file.
WARNING: Variable dx8 was not found on DATA file.
WARNING: Variable dx9 was not found on DATA file.
WARNING: Variable dx10 was not found on DATA file.
NOTE: There were 1 observations read from the data set WORK.ADD.
NOTE: 1 observations added.
NOTE: The data set WORK.BASE has 2 observations and 10 variables.
&lt;/PRE&gt;
&lt;P&gt;If you want to get rid of the WARNING messages you could just add the extra variables when you make the copy of the data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro bta(fy);
libname bta "/bta/tdata/fy&amp;amp;fy.";

data tdata ;
  set bta.teddy ;
  if tflflag = "U" and place="26" then delete;
  array dx (25) ;
run;

** Remove any duplicate records **;
proc sort data=tdata nodupkey;
  by _all_;
run;

** Append to one data set **;
proc append data = tdata base = crc.tdata;
run;

** Clean up **;
proc delete data=tdata;
run;

%mend bta;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Dec 2018 17:42:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Mashing-datasets-with-different-varaibles/m-p/523675#M142293</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-12-27T17:42:50Z</dc:date>
    </item>
    <item>
      <title>Re: Mashing datasets with different varaibles</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Mashing-datasets-with-different-varaibles/m-p/523705#M142311</link>
      <description>&lt;P&gt;Tom,&lt;/P&gt;
&lt;P&gt;Thanks for the reply! Yours is probably the correct answer but I'm having trouble implementing it as the DX1-DX8 in the first file have different length than those in the other files and so the Proc Append fails to add DX9-DX25.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Brian&lt;/P&gt;</description>
      <pubDate>Thu, 27 Dec 2018 20:19:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Mashing-datasets-with-different-varaibles/m-p/523705#M142311</guid>
      <dc:creator>BTAinRVA</dc:creator>
      <dc:date>2018-12-27T20:19:51Z</dc:date>
    </item>
    <item>
      <title>Re: Mashing datasets with different varaibles</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Mashing-datasets-with-different-varaibles/m-p/523706#M142312</link>
      <description>When using PROC APPEND make sure to define the BASE dataset with the attributes you want before appending any the actual datasets.&lt;BR /&gt;You can use the FORCE option, but that just means the step will run even if the new dataset has extra variables, but it does not mean that the extra variables are actually added to the BASE dataset.  Instead the extra variables are ignored.&lt;BR /&gt;</description>
      <pubDate>Thu, 27 Dec 2018 20:43:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Mashing-datasets-with-different-varaibles/m-p/523706#M142312</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-12-27T20:43:02Z</dc:date>
    </item>
  </channel>
</rss>

