<?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 to add date suffix to dataset name in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Add-to-add-date-suffix-to-dataset-name/m-p/283788#M57848</link>
    <description>&lt;P&gt;Do not recreate your datasets, rename them. Use the CHANGE syntax&amp;nbsp;in PROC DATASETS.&lt;/P&gt;
&lt;P&gt;You can use intnx + %sysfunc to create your macro variable, or use&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9﻿&lt;/a&gt;&amp;nbsp;suggestions for the macro variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class;
	set sashelp.class sashelp.class(obs=5);
run;

%let suffix = %sysfunc(intnx(month, %sysfunc(today()), -6, b) , yyq10.);
%put	&amp;amp;suffix;

proc datasets lib=work nodetails nolist;
	change class=class_&amp;amp;suffix;
	run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 12 Jul 2016 14:54:13 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-07-12T14:54:13Z</dc:date>
    <item>
      <title>Add to add date suffix to dataset name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-to-add-date-suffix-to-dataset-name/m-p/283782#M57845</link>
      <description>&lt;P&gt;I want to create a macro to add 2016Q1 to dataset name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;suppose my table name is :&amp;nbsp; Auto&lt;/P&gt;&lt;P&gt;After running the macro it should be:&amp;nbsp;&amp;nbsp;&amp;nbsp; Auto_2016Q1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Similarly for other table in that library.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i have one macro: but it showing error:&lt;/P&gt;&lt;P&gt;data&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;_null_&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="3" face="Courier New"&gt;&lt;FONT size="3" face="Courier New"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;CALL &lt;FONT size="3" face="Courier New"&gt;&lt;FONT size="3" face="Courier New"&gt;SYMPUT(&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#800080" size="3" face="Courier New"&gt;&lt;FONT color="#800080" size="3" face="Courier New"&gt;&lt;FONT color="#800080" size="3" face="Courier New"&gt;'thisq'&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="3" face="Courier New"&gt;&lt;FONT size="3" face="Courier New"&gt;, Put(mdy((month(today())), &lt;/FONT&gt;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" size="3" face="Courier New"&gt;&lt;FONT color="#008080" size="3" face="Courier New"&gt;&lt;FONT color="#008080" size="3" face="Courier New"&gt;1&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT size="3" face="Courier New"&gt;&lt;FONT size="3" face="Courier New"&gt;, (year(today()))), &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#008080" size="3" face="Courier New"&gt;&lt;FONT color="#008080" size="3" face="Courier New"&gt;&lt;FONT color="#008080" size="3" face="Courier New"&gt;yyq10.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="3" face="Courier New"&gt;&lt;FONT size="3" face="Courier New"&gt;));&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;run&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;FONT size="3" face="Courier New"&gt;&lt;FONT size="3" face="Courier New"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;　&lt;/P&gt;&lt;P&gt;PROC &lt;STRONG&gt;&lt;FONT color="#000080" size="3" face="Courier New"&gt;&lt;FONT color="#000080" size="3" face="Courier New"&gt;&lt;FONT color="#000080" size="3" face="Courier New"&gt;SQL&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT size="3" face="Courier New"&gt;&lt;FONT size="3" face="Courier New"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;CREATE&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" size="3" face="Courier New"&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;TABLE&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="3" face="Courier New"&gt;&lt;FONT size="3" face="Courier New"&gt; CURRENT.TDATE&amp;amp;thisq &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;AS&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" size="3" face="Courier New"&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;SELECT&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="3" face="Courier New"&gt;&lt;FONT size="3" face="Courier New"&gt; ACTUAL_DT,DATE_SK &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;&lt;FONT color="#0000ff" size="3" face="Courier New"&gt;FROM&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size="3" face="Courier New"&gt;&lt;FONT size="3" face="Courier New"&gt; ORACLE.TDATE;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;QUIT&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;FONT size="3" face="Courier New"&gt;&lt;FONT size="3" face="Courier New"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;25 CURRENT.TDATE 2016Q3&lt;/P&gt;&lt;P&gt;____&lt;/P&gt;&lt;P&gt;22&lt;/P&gt;&lt;P&gt;200&lt;/P&gt;&lt;P&gt;ERROR 22-322: Syntax error, expecting one of the following: (, AS, LIKE&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jul 2016 14:31:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-to-add-date-suffix-to-dataset-name/m-p/283782#M57845</guid>
      <dc:creator>subrat1</dc:creator>
      <dc:date>2016-07-12T14:31:48Z</dc:date>
    </item>
    <item>
      <title>Re: Add to add date suffix to dataset name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-to-add-date-suffix-to-dataset-name/m-p/283787#M57847</link>
      <description>&lt;P&gt;Use call symputx(), will strip off blanks, or you could use %trim() around it. &amp;nbsp;Some tips however:&lt;/P&gt;
&lt;P&gt;Avoid using data - in this case year and quarter - in dataset names, as this will make your programming (and others if they use it) harder. &amp;nbsp;Using one dataset, and putting year and quarter in as variables both allows you to filter the data based on that date, and do something called by group processing which makes your life so much easier.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Avoid mixed case on your code, makes it harder to reead and use indetation consistently to make your code as readable as possible. &amp;nbsp;You can also use the code blocks ( {i} above your post) to higlight code, e.g:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  if a=1 then do;
    abc="Do something"
  end;
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Jul 2016 14:47:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-to-add-date-suffix-to-dataset-name/m-p/283787#M57847</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-07-12T14:47:01Z</dc:date>
    </item>
    <item>
      <title>Re: Add to add date suffix to dataset name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-to-add-date-suffix-to-dataset-name/m-p/283788#M57848</link>
      <description>&lt;P&gt;Do not recreate your datasets, rename them. Use the CHANGE syntax&amp;nbsp;in PROC DATASETS.&lt;/P&gt;
&lt;P&gt;You can use intnx + %sysfunc to create your macro variable, or use&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9﻿&lt;/a&gt;&amp;nbsp;suggestions for the macro variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class;
	set sashelp.class sashelp.class(obs=5);
run;

%let suffix = %sysfunc(intnx(month, %sysfunc(today()), -6, b) , yyq10.);
%put	&amp;amp;suffix;

proc datasets lib=work nodetails nolist;
	change class=class_&amp;amp;suffix;
	run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Jul 2016 14:54:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-to-add-date-suffix-to-dataset-name/m-p/283788#M57848</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-07-12T14:54:13Z</dc:date>
    </item>
    <item>
      <title>Re: Add to add date suffix to dataset name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-to-add-date-suffix-to-dataset-name/m-p/283792#M57851</link>
      <description>&lt;P&gt;Two items, given that you have already received a valid suggestion (switching from SYMPUT to SYMPUTX).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First, you will also need to insert the underscore if you want that as part of the name:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;current.tdate_&amp;amp;thisq&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second, why did the problem occur in the first place?&amp;nbsp; Well, date formats are centered.&amp;nbsp; You are creating a 6-character string (2015Q3) but using a 10-character format.&amp;nbsp; So there are two leading blanks and two trailing blanks as part of the value of the macro variable.&amp;nbsp; CALL SYMPUTX automatically removes leading and trailing blanks when creating a macro variable.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jul 2016 15:00:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-to-add-date-suffix-to-dataset-name/m-p/283792#M57851</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-07-12T15:00:16Z</dc:date>
    </item>
    <item>
      <title>Re: Add to add date suffix to dataset name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-to-add-date-suffix-to-dataset-name/m-p/828347#M327213</link>
      <description>&lt;P&gt;As indicated by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;, you should use SYMPUTX instead of SYMPUT when storing macro variable values from a DATA step to ensure that leading and trailing blanks are stripped from the value before is it stored. For example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  call symput('SymputThisQ'  , put(today(),yyq10.));
  call symputx('SymputXThisQ', put(today(),yyq10.));
run;
%put NOTE: SymputThisQ: **&amp;amp;SymputDate**;
%put NOTE: SymputXThisQ: **&amp;amp;SymputXDate**;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The asterisks allow you to see that the value created with SYMPUT includes leading spaces.&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;NOTE: SymputThisQ: **&amp;nbsp;&amp;nbsp;&amp;nbsp; 2022Q3**&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;NOTE: SymputXThisQ: **2022Q3**&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;I often use PROC SQL with the TRIMMED specification to do something similar with SQL:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select put(today(),yyq10.)
   into :SQLThisQ &lt;STRONG&gt;trimmed&lt;/STRONG&gt;
   from sashelp.cars(obs=1)
;
quit;

%put NOTE: SQLDate: **&amp;amp;SQLThisQ**;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;NOTE: SQLDate: **2022Q3**&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;You could combine this technique with the renaming option suggested by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select put(today(),yyq10.)
   into :ThisQ trimmed
   from sashelp.cars(obs=1)
;
create table work.cars as 
	select *
		from sashelp.cars(obs=5)
;
quit;

proc datasets lib=work nodetails nolist;
	change cars=cars_&amp;amp;ThisQ;
	run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;NOTE: Changing the name WORK.CARS to WORK.CARS_2022Q3 (memtype=DATA).&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;But I personally prefer to just generate the text in-line with my code using macro functions. For example, this code can generate the date-related text on the fly:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put **%qsysfunc(strip(%qsysfunc(today(),yyq10.)))**;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;**2022Q3**&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;So this code does the whole job in one step without requiring you to set a macro variable value:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table work.carDate_%sysfunc(strip(%qsysfunc(today(),yyq10.))) as 
	select *
		from sashelp.cars(obs=5)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;NOTE: Table WORK.CARDATE_2022Q3 created, with 5 rows and 15 columns.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;May the SAS be with you!&lt;BR /&gt;Mark&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Aug 2022 18:21:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-to-add-date-suffix-to-dataset-name/m-p/828347#M327213</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2022-08-11T18:21:59Z</dc:date>
    </item>
  </channel>
</rss>

