<?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: Add a variable by Macro. Half way done. in SAS Data Science</title>
    <link>https://communities.sas.com/t5/SAS-Data-Science/Add-a-variable-by-Macro-Half-way-done/m-p/319418#M4796</link>
    <description>&lt;P&gt;a line taken from your macro:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%if %sysfunc(&lt;STRONG&gt;exist&lt;/STRONG&gt;(&amp;amp;fname)) %then &amp;amp;fname ;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;are you sure that 2016&lt;STRONG&gt;12 &lt;/STRONG&gt;already exists ?&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 16 Dec 2016 00:55:11 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2016-12-16T00:55:11Z</dc:date>
    <item>
      <title>Add a variable by Macro. Half way done.</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Add-a-variable-by-Macro-Half-way-done/m-p/319399#M4792</link>
      <description>&lt;P&gt;Hello Guys,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have been trying to append tables together by marco way, and it was successful. Furthermore, I wanted to add one more column to each table to display the year and mnth.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For eg:&lt;/P&gt;&lt;P&gt;Data pulled from 201610 (2016 Oct), will have an additonal&amp;nbsp;column to display 201610 accordingly.&lt;/P&gt;&lt;P&gt;Data pulled from 201611 (2016 Nov), will have an additonal column to display 201611 accordingly.&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;All the way to 201301 (2013 Jan).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have successfully append all the tables from 201301 to 201611, but I just could not figure out how to add an additional column to display the according month.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below its my code for appending tables with Macro, could any body help me to modify my code to add an additional column?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt; &lt;STRONG&gt;&lt;EM&gt;product&lt;/EM&gt;&lt;/STRONG&gt;;&amp;nbsp; &amp;nbsp;/*This is the Macro code to generate statment with format MCCYYYYMM.MALD_STMT. */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%local year month fname ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%do year=&lt;STRONG&gt;2013&lt;/STRONG&gt; %to &lt;STRONG&gt;2016&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; %do month=&lt;STRONG&gt;1&lt;/STRONG&gt; %to &lt;STRONG&gt;12&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let fname=MC&amp;amp;year.%sysfunc(putn(&amp;amp;month,Z2)).Acct;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %if %sysfunc(exist(&amp;amp;fname)) %then &amp;amp;fname ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; TotalStatement ;&amp;nbsp; &amp;nbsp;/*this is the step to append all the Acct tables from MC201301 TO MC201612. */&lt;/P&gt;&lt;P&gt;set %&lt;STRONG&gt;&lt;EM&gt;product&lt;/EM&gt;&lt;/STRONG&gt; ;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2016 22:26:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Add-a-variable-by-Macro-Half-way-done/m-p/319399#M4792</guid>
      <dc:creator>肉肉</dc:creator>
      <dc:date>2016-12-15T22:26:21Z</dc:date>
    </item>
    <item>
      <title>Re: Add a variable by Macro. Half way done.</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Add-a-variable-by-Macro-Half-way-done/m-p/319400#M4793</link>
      <description>&lt;P&gt;Two things: You may be creating extra work work. It looks like you could use a shortcut list to combine your sets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data TotalStatement ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set MC: ;&amp;nbsp; &amp;lt;= Note the : immediately after the C&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Will combine all of your data sets that start with MC. Or possibly: Set MC20: ; to get the sets that start with MC20. If they are all in a library other than work just add the library:&amp;nbsp; set MyLib.MC20:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second is to use the option INDSNAME that would tell you the name of the source file:&lt;/P&gt;
&lt;P&gt;data TotalStatement ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set MC: indsname=tempname;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; length datasetname $ 41;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; datasetname = tempname;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;Or you could parse the tempname variable for your date information. The Indsname option creates a temporary variable that is not added to the dataset. By creating a separate variable that is permanent we can assign the value and keep it.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2016 22:41:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Add-a-variable-by-Macro-Half-way-done/m-p/319400#M4793</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-12-15T22:41:54Z</dc:date>
    </item>
    <item>
      <title>Re: Add a variable by Macro. Half way done.</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Add-a-variable-by-Macro-Half-way-done/m-p/319402#M4794</link>
      <description>&lt;P&gt;Hi ballardw,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your help.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It kinds worked, but did not help to get exactly I wanted.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The story is...every month has a table which contains about 612k observations, but it did not have "month" indicator, and I need to add one, so I know which month the data was pulled from. The library name is MC201611, MC201610.....MC201301(there are more, till 200801).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I wanted was to add a column to indicate the month, so when I pull one observation, I know which month it was from.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this will clear the confusion before.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ro&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2016 23:19:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Add-a-variable-by-Macro-Half-way-done/m-p/319402#M4794</guid>
      <dc:creator>肉肉</dc:creator>
      <dc:date>2016-12-15T23:19:30Z</dc:date>
    </item>
    <item>
      <title>Re: Add a variable by Macro. Half way done.</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Add-a-variable-by-Macro-Half-way-done/m-p/319412#M4795</link>
      <description>&lt;P&gt;Are youe dealing with LIBRARY of MC201611 or DATASET MC201611? They are slightly different and would appear in a different location in the dataset name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the datasetname is MC201611 the you could do either:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="SAS Monospace" size="2"&gt;Month= compress(tempname,,&lt;/FONT&gt;&lt;FONT color="#800080" face="SAS Monospace" size="2"&gt;'DK'&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="SAS Monospace" size="2"&gt;which would yield 201611 as a character variable&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="SAS Monospace" size="2"&gt;OR do you want an actual SAS date value?&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="SAS Monospace" size="2"&gt;Month= input(compress(tempname,,&lt;FONT color="#800080" face="SAS Monospace" size="2"&gt;'DK'&lt;/FONT&gt;),YYMM6.);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="SAS Monospace" size="2"&gt;format Month YYMMN6.;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Dec 2016 00:21:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Add-a-variable-by-Macro-Half-way-done/m-p/319412#M4795</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-12-16T00:21:51Z</dc:date>
    </item>
    <item>
      <title>Re: Add a variable by Macro. Half way done.</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Add-a-variable-by-Macro-Half-way-done/m-p/319418#M4796</link>
      <description>&lt;P&gt;a line taken from your macro:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%if %sysfunc(&lt;STRONG&gt;exist&lt;/STRONG&gt;(&amp;amp;fname)) %then &amp;amp;fname ;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;are you sure that 2016&lt;STRONG&gt;12 &lt;/STRONG&gt;already exists ?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Dec 2016 00:55:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Add-a-variable-by-Macro-Half-way-done/m-p/319418#M4796</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-12-16T00:55:11Z</dc:date>
    </item>
    <item>
      <title>Re: Add a variable by Macro. Half way done.</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Add-a-variable-by-Macro-Half-way-done/m-p/319444#M4797</link>
      <description>&lt;P&gt;it would be data set&amp;nbsp;which are named as&amp;nbsp;'MC201611.ACCT', 'MC201610.ACCT', 'MC2016.ACCT'......all the way to 'MC201301.ACCT'. I will need to append them together, with a column named 'MONTH' which works as indicator to display cooresponding month that the data sets were pulled from.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;did this help you to understando&amp;nbsp;what I am trying to achieve?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ro&lt;/P&gt;</description>
      <pubDate>Fri, 16 Dec 2016 04:27:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Add-a-variable-by-Macro-Half-way-done/m-p/319444#M4797</guid>
      <dc:creator>肉肉</dc:creator>
      <dc:date>2016-12-16T04:27:11Z</dc:date>
    </item>
    <item>
      <title>Re: Add a variable by Macro. Half way done.</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Add-a-variable-by-Macro-Half-way-done/m-p/319445#M4798</link>
      <description>&lt;P&gt;I guess, if its not&amp;nbsp;existing, it would not be appended. it worked for me.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Dec 2016 04:28:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Add-a-variable-by-Macro-Half-way-done/m-p/319445#M4798</guid>
      <dc:creator>肉肉</dc:creator>
      <dc:date>2016-12-16T04:28:15Z</dc:date>
    </item>
    <item>
      <title>Re: Add a variable by Macro. Half way done.</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Add-a-variable-by-Macro-Half-way-done/m-p/319578#M4800</link>
      <description>&lt;P&gt;How about selecting the ones that exist that the current SAS session knows about:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql noprint;
   select catx('.',libname,memname) into : sets separated by ' '
   from dictionary.members 
   where substr(LIBNAME,1,3)='MC2' and memname="ACCT";
quit;


data TotalStatement ;
   set &amp;amp;sets indsname=tempname;
    length datasetname $ 41;
    Month= compress(tempname,,'DK');
    Monthdate= input(compress(tempname,,'DK'),YYMM6.);
    Format Monthdate YYMMN6.;
run;&lt;/PRE&gt;
&lt;P&gt;The Proc SQL section finds all of the libraries that start with MC2 and have a data set named ACCT and put them into a macro variable which is used in SET statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Dec 2016 16:12:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Add-a-variable-by-Macro-Half-way-done/m-p/319578#M4800</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-12-16T16:12:48Z</dc:date>
    </item>
    <item>
      <title>Re: Add a variable by Macro. Half way done.</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Add-a-variable-by-Macro-Half-way-done/m-p/319649#M4803</link>
      <description>&lt;P&gt;To check you code I made a sligh change:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro product;   /*This is the Macro code to generate statment with format MCCYYYYMM.MALD_STMT. */
%local year month fname ;
%do year=2013 %to 2016;
   %do month=1 %to 12;
       %let fname=MC&amp;amp;year.%sysfunc(putn(&amp;amp;month,Z2)).Acct;
      /*  %if %sysfunc(exist(&amp;amp;fname)) %then &amp;amp;fname ; &lt;STRONG&gt; &amp;lt;&amp;lt;&amp;lt; line replaced by next one&lt;/STRONG&gt; */
       %put &amp;amp;FNAME;       
    %end;
 %end;
 %mend;
 
data TotalStatement ;   /*this is the step to append all the Acct tables from MC201301 TO MC201612. */
  set %product ;
    ;    &lt;STRONG&gt;/* &amp;lt;&amp;lt;&amp;lt; one more semicolon added to close SET statement */&lt;/STRONG&gt;&lt;BR /&gt;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;check generated code by macro in the log. All file names created as expected;&lt;/P&gt;
&lt;P&gt;if file MC201612.acct exists then the only real change is adding the semicolon after set statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Dec 2016 20:59:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Add-a-variable-by-Macro-Half-way-done/m-p/319649#M4803</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-12-16T20:59:06Z</dc:date>
    </item>
  </channel>
</rss>

