<?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: Using an Alias to Determine a Dataset in the Data Step in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Using-an-Alias-to-Determine-a-Dataset-in-the-Data-Step/m-p/250563#M56599</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sorry, you seem to be trying to handle "data" in every possible way other than using Base SAS which is designed to work on data? &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Lets start with the naming convention. &amp;nbsp;Why do you want to have parts of a date in the name of the dataset. &amp;nbsp;This causes two problems straight off the bat, firstly, how do you refence that dataset and others in code, you then need to work out a whole method of identifying what the datasets are called. &amp;nbsp;Secondly, if you need to use that date information in coding, you have to work out what datasets are to be used, then extract this from name, then use it. &amp;nbsp;All of the above causes a lot more work, and I don't see any gain from it? &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Secondly, macro language is a text generator, it has no functionality directly for processing of date format data or numeric data. &amp;nbsp;So why do all the date processing in this, it will just add additional, and obfuscated code to your process. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An alternative solution is to have a main dataset - call it main in this example, which is added to, and it has a column for date:&lt;/P&gt;
&lt;P&gt;MAIN&lt;/P&gt;
&lt;P&gt;DATE &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;your_variables&amp;gt;&lt;/P&gt;
&lt;P&gt;01JAN2014 &amp;nbsp;...&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What does the above do, well, firstly all you subsequent code needs to know is that the data is to be found in a dataset called main - simplfies the coding - then, if I only want to see data from JAN2014, I can simply where clause out for that date in Base SAS datastep code. &amp;nbsp;Another example, say you want to do a basic print on the data, you need to get a list of the files and then loop over them, creating a title for each one, and a filename etc. &amp;nbsp;However in one dataset, you can use by group processing - which is generally faster - to do all that, including titles. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To note, if ou have to do the date manipulation, do it in a datastep, then call symput:&lt;/P&gt;
&lt;PRE&gt;data _null_;
  dt=intnx('month','21dec2015'd,0,"End");
  call symput(filename,cats("tablename_",year(dt),"_",month(dt)));
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 17 Feb 2016 11:03:15 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2016-02-17T11:03:15Z</dc:date>
    <item>
      <title>Using an Alias to Determine a Dataset in the Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-an-Alias-to-Determine-a-Dataset-in-the-Data-Step/m-p/250561#M56598</link>
      <description>&lt;P&gt;Hi guys,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to dynamically set the dataset name based on a variable (dtmMonthEndDate) input at the start of my&amp;nbsp;procedure. &amp;nbsp;My code looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;* Enter the month ;
%Let dtmMonthEndDate = Intnx('Month', '31Dec2015'd, 0, "End") ;

* Format = YYYYMM ;
%Let strMonth = Put(&amp;amp;dtmMonthEndDate., yymmn6.) ;

%Let Filename = Compress("TableName_"||Year(&amp;amp;dtmMonthEndDate.)||"_"||SubStr(&amp;amp;strMonth., 5, 2)) ;

Data Work.MyData ;

	Merge
		"&amp;amp;Filename."
			(
			Keep = Ref_ID Segment_00
			In = a
			)
		Work.Table_1
			(
			Keep = _All_
			In = x
			) ;

	If x ;

	By Ref_ID ;

Run ;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The table name&amp;nbsp;should look like this: &amp;nbsp;"TableName_2015_12", with the 2015 denoting the year and 12 the month.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The variables are fine when using them in any other part of the step; for example, when puting the filename into a column, but when I try to use it for a dataset name, the compress function is causing errors.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone know how to circumvent this problem? &amp;nbsp;I've searched like mad online and come up short. &amp;nbsp;Any help would be great.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using SAS EGP version 6.1. &amp;nbsp;Let me know if you need any further info?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Jamie&lt;/P&gt;</description>
      <pubDate>Wed, 17 Feb 2016 10:46:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-an-Alias-to-Determine-a-Dataset-in-the-Data-Step/m-p/250561#M56598</guid>
      <dc:creator>JamieFay</dc:creator>
      <dc:date>2016-02-17T10:46:03Z</dc:date>
    </item>
    <item>
      <title>Re: Using an Alias to Determine a Dataset in the Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-an-Alias-to-Determine-a-Dataset-in-the-Data-Step/m-p/250563#M56599</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sorry, you seem to be trying to handle "data" in every possible way other than using Base SAS which is designed to work on data? &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Lets start with the naming convention. &amp;nbsp;Why do you want to have parts of a date in the name of the dataset. &amp;nbsp;This causes two problems straight off the bat, firstly, how do you refence that dataset and others in code, you then need to work out a whole method of identifying what the datasets are called. &amp;nbsp;Secondly, if you need to use that date information in coding, you have to work out what datasets are to be used, then extract this from name, then use it. &amp;nbsp;All of the above causes a lot more work, and I don't see any gain from it? &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Secondly, macro language is a text generator, it has no functionality directly for processing of date format data or numeric data. &amp;nbsp;So why do all the date processing in this, it will just add additional, and obfuscated code to your process. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An alternative solution is to have a main dataset - call it main in this example, which is added to, and it has a column for date:&lt;/P&gt;
&lt;P&gt;MAIN&lt;/P&gt;
&lt;P&gt;DATE &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;your_variables&amp;gt;&lt;/P&gt;
&lt;P&gt;01JAN2014 &amp;nbsp;...&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What does the above do, well, firstly all you subsequent code needs to know is that the data is to be found in a dataset called main - simplfies the coding - then, if I only want to see data from JAN2014, I can simply where clause out for that date in Base SAS datastep code. &amp;nbsp;Another example, say you want to do a basic print on the data, you need to get a list of the files and then loop over them, creating a title for each one, and a filename etc. &amp;nbsp;However in one dataset, you can use by group processing - which is generally faster - to do all that, including titles. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To note, if ou have to do the date manipulation, do it in a datastep, then call symput:&lt;/P&gt;
&lt;PRE&gt;data _null_;
  dt=intnx('month','21dec2015'd,0,"End");
  call symput(filename,cats("tablename_",year(dt),"_",month(dt)));
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Feb 2016 11:03:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-an-Alias-to-Determine-a-Dataset-in-the-Data-Step/m-p/250563#M56599</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-02-17T11:03:15Z</dc:date>
    </item>
    <item>
      <title>Re: Using an Alias to Determine a Dataset in the Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-an-Alias-to-Determine-a-Dataset-in-the-Data-Step/m-p/250576#M56602</link>
      <description>&lt;P&gt;You make this unnecessary complicated. Since you only need month and year of the date, the inetrmediate step with intnx is useless&lt;/P&gt;
&lt;P&gt;Therefore&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let date='31dec2015'd;

data _null_;
call symput('strmonth',put(year(&amp;amp;date,z4.))!!'_'!!put(month(&amp;amp;date,z2.)));
run;

%let filename=Tablename_&amp;amp;strmonth;

data work.mydata;
merge
  &amp;amp;filename
.........&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You may need to insert a library specification immediately before &amp;amp;filename in the MERGE, if your table is not in WORK:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;amp;libname..&amp;amp;filename&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Feb 2016 11:42:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-an-Alias-to-Determine-a-Dataset-in-the-Data-Step/m-p/250576#M56602</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-02-17T11:42:59Z</dc:date>
    </item>
    <item>
      <title>Re: Using an Alias to Determine a Dataset in the Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-an-Alias-to-Determine-a-Dataset-in-the-Data-Step/m-p/250590#M56603</link>
      <description>&lt;P&gt;Kurt, you're the winner! &amp;nbsp;My final codes looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;* Variables available ;
%Let dtmMonthEndDate = Intnx('Month', '31Dec2015'd, 0, "End") ;

Data _Null_ ;

	Call SymPut('strMonth', Put(Compress("TableName_"||Year(&amp;amp;dtmMonthEndDate)!!'_'!!Month(&amp;amp;dtmMonthEndDate)), $40.)) ;

	%Let Filename = &amp;amp;strMonth ;

Run ;

Data Work.Dynamic_Test_1 ;

	Merge 
		MyLibName.&amp;amp;Filename.&lt;/PRE&gt;&lt;P&gt;Thanks for all your help guys!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Jamie&lt;/P&gt;</description>
      <pubDate>Wed, 17 Feb 2016 12:15:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-an-Alias-to-Determine-a-Dataset-in-the-Data-Step/m-p/250590#M56603</guid>
      <dc:creator>JamieFay</dc:creator>
      <dc:date>2016-02-17T12:15:30Z</dc:date>
    </item>
    <item>
      <title>Re: Using an Alias to Determine a Dataset in the Data Step</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-an-Alias-to-Determine-a-Dataset-in-the-Data-Step/m-p/250592#M56604</link>
      <description>&lt;P&gt;Pleasure &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Feb 2016 12:24:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-an-Alias-to-Determine-a-Dataset-in-the-Data-Step/m-p/250592#M56604</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-02-17T12:24:51Z</dc:date>
    </item>
  </channel>
</rss>

