<?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: Symput to create a macro variable in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Symput-to-create-a-macro-variable/m-p/234731#M5935</link>
    <description>&lt;P&gt;Got it and I just tested and it worked great. Thanks so much.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the second question, If I write DATA sub2002 - sub2014, SAS will give error messages? Or I have to spell each of the output dataset names DADA sub2002 subs2003 sub2004 sub2005....? Is there a way not to list each one of them?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 14px; line-height: 20px;"&gt;DATA sub2002 - sub2014;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;SET mydata&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;%macro get();&lt;BR /&gt;&amp;nbsp; &amp;nbsp;%do year=2002 %to 2014;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;%let nextyr=%eval(&amp;amp;year.+1);&lt;BR /&gt;&amp;nbsp; &amp;nbsp;if effective_date &amp;lt;= "31mar&amp;amp;nextyr."d and (end_date &amp;gt;= "1apr&amp;amp;year."d or end_date = .) then output sub&amp;amp;year;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;%end;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;%mend;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;%get;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 13 Nov 2015 23:08:43 GMT</pubDate>
    <dc:creator>Solph</dc:creator>
    <dc:date>2015-11-13T23:08:43Z</dc:date>
    <item>
      <title>Symput to create a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Symput-to-create-a-macro-variable/m-p/234722#M5932</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm using %do year= 2002 &amp;nbsp;%to 2014 to select cases and output resutls.&amp;nbsp;When I select cases, I'm using&amp;nbsp;two year values, say var1=2002 and &amp;nbsp;var2=2003, or var1=2003 and var2=2004, etc.,, What makes this complicate is the year 2 variable (with next year's value) is embended in a date format (e.g. var1='1apr2002'd and var2="31mar2003"d.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I thought the following code would work, but it didn't (log is attached at the end).&amp;nbsp;I'm using more years of data but here I have show 3 years.&lt;/P&gt;
&lt;P&gt;- Am I using Symput wrong - is it that I can't put a macro variabe (&amp;amp;year) in the second argument?&lt;/P&gt;
&lt;P&gt;- A related question. It worked if I simply just repeated the same line 13 times using different year values (such as lines 3-5 of the sample SAS code below). What didn't work is I wrote a series of output data set names &amp;nbsp;as DATA d2002-d2014 - SAS didn't regconize all datasets (d2002 d2003 d2004 d2005 etc.) and thus would not output data to some of the dataset. Is there a way to get around?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sorry that I don't have a sample data for you to run. I'll just take your&amp;nbsp;suggestions and apply to my data and report back.&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;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA d2002 d2003 d2004 subdata2002 subdata2003 subdata2004;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; SET mydata&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; if effective_date &amp;lt;= '31mar2003'd and (end_date &amp;gt;= '1apr2002'd or end_date = .) then output d2002; &amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; if effective_date &amp;lt;= '31mar2004'd and (end_date &amp;gt;= '1apr2003'd or end_date = .) then output d2003; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; if effective_date &amp;lt;= '31mar2005'd and (end_date &amp;gt;= '1apr2004'd or end_date = .) then output d2004; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;%macro get();&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; %do year=2002 %to 2004;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; call symput('nextyr',1+&amp;amp;year.);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if effective_date &amp;lt;= "31mar&amp;amp;nextyr."d and (end_date &amp;gt;= "1apr&amp;amp;year."d or end_date = .) then output subdata&amp;amp;year;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; %end;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;%mend;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; %get;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;LOG:&lt;/P&gt;
&lt;P&gt;34 %macro get();&lt;BR /&gt;35 &lt;BR /&gt;36 %do year=2002 %to 2003;&lt;BR /&gt;37 call symput('nextyr',1+&amp;amp;year.);&lt;BR /&gt;38 if effective_date &amp;lt;= "31mar&amp;amp;nextyr."d and (end_date &amp;gt;= "1apr&amp;amp;year."d or end_date = .) then output postal&amp;amp;year;&lt;BR /&gt;39 %end;&lt;BR /&gt;40 %mend;&lt;BR /&gt;41 %get;&lt;BR /&gt;NOTE: Line generated by the invoked macro "GET".&lt;BR /&gt;41 call symput('nextyr',1+&amp;amp;year.); if effective_date &amp;lt;= "31mar&amp;amp;nextyr."d and (end_date &amp;gt;= "1apr&amp;amp;year."d or end_date = .)&lt;BR /&gt; ________________&lt;BR /&gt; 77&lt;BR /&gt;41 ! then output postal&amp;amp;year;&lt;BR /&gt;MPRINT(GET): call symput('nextyr',1+2002);&lt;BR /&gt;WARNING: Apparent symbolic reference NEXTYR not resolved.&lt;BR /&gt;ERROR: Invalid date/time/datetime constant "31mar&amp;amp;nextyr."d.&lt;BR /&gt;MPRINT(GET): if effective_date &amp;lt;= "31mar&amp;amp;nextyr."d and (end_date &amp;gt;= "1apr2002"d or end_date = .) then output postal2002;&lt;BR /&gt;MPRINT(GET): call symput('nextyr',1+2003);&lt;BR /&gt;WARNING: Apparent symbolic reference NEXTYR not resolved.&lt;BR /&gt;MPRINT(GET): if effective_date &amp;lt;= "31mar&amp;amp;nextyr."d and (end_date &amp;gt;= "1apr2003"d or end_date = .) then output postal2003;&lt;BR /&gt;ERROR 77-185: Invalid number conversion on "31mar&amp;amp;nextyr."d.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Nov 2015 22:19:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Symput-to-create-a-macro-variable/m-p/234722#M5932</guid>
      <dc:creator>Solph</dc:creator>
      <dc:date>2015-11-13T22:19:31Z</dc:date>
    </item>
    <item>
      <title>Re: Symput to create a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Symput-to-create-a-macro-variable/m-p/234726#M5934</link>
      <description>&lt;P&gt;You seem to be confusing CALL SYMPUT which is a data step statement that can only work WHILE THE DATA STEP IS RUNNING with %LET which can be used to assign macro variable values WHILE THE MACRO IS RUNNING.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro get();
%do year=2002 %to 2004;
  %let nextyr = %eval(&amp;amp;year +1);
          
if effective_date &amp;lt;= "31mar&amp;amp;nextyr."d and (end_date &amp;gt;= "01apr&amp;amp;year."d or end_date = .) then output subdata&amp;amp;year;      

%end;
%mend;


DATA d2002 d2003 d2004 subdata2002 subdata2003 subdata2004;
    SET mydata
    if effective_date &amp;lt;= '31mar2003'd and (end_date &amp;gt;= '01apr2002'd or end_date = .) then output d2002;  
    if effective_date &amp;lt;= '31mar2004'd and (end_date &amp;gt;= '01apr2003'd or end_date = .) then output d2003;  
    if effective_date &amp;lt;= '31mar2005'd and (end_date &amp;gt;= '01apr2004'd or end_date = .) then output d2004;  
    %get;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 Nov 2015 22:43:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Symput-to-create-a-macro-variable/m-p/234726#M5934</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2015-11-13T22:43:11Z</dc:date>
    </item>
    <item>
      <title>Re: Symput to create a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Symput-to-create-a-macro-variable/m-p/234731#M5935</link>
      <description>&lt;P&gt;Got it and I just tested and it worked great. Thanks so much.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the second question, If I write DATA sub2002 - sub2014, SAS will give error messages? Or I have to spell each of the output dataset names DADA sub2002 subs2003 sub2004 sub2005....? Is there a way not to list each one of them?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 14px; line-height: 20px;"&gt;DATA sub2002 - sub2014;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;SET mydata&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;%macro get();&lt;BR /&gt;&amp;nbsp; &amp;nbsp;%do year=2002 %to 2014;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;%let nextyr=%eval(&amp;amp;year.+1);&lt;BR /&gt;&amp;nbsp; &amp;nbsp;if effective_date &amp;lt;= "31mar&amp;amp;nextyr."d and (end_date &amp;gt;= "1apr&amp;amp;year."d or end_date = .) then output sub&amp;amp;year;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;%end;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;%mend;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;%get;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Nov 2015 23:08:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Symput-to-create-a-macro-variable/m-p/234731#M5935</guid>
      <dc:creator>Solph</dc:creator>
      <dc:date>2015-11-13T23:08:43Z</dc:date>
    </item>
    <item>
      <title>Re: Symput to create a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Symput-to-create-a-macro-variable/m-p/234734#M5936</link>
      <description>&lt;P&gt;You cannot use ranges of datasets in a DATA statement. &amp;nbsp;You could use macro code to generate the names.&lt;/P&gt;
&lt;P&gt;It is probably easier if you generate the whole data step with the macro.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro get(start,stop,inputds);
DATA 
%do year=&amp;amp;start %to &amp;amp;stop;
   sub&amp;amp;year 
%end;
;
   SET &amp;amp;inputds;
%do year=&amp;amp;start %to &amp;amp;stop;
   if effective_date &amp;lt;= "31mar%eval(&amp;amp;year+1)"d
     and (end_date &amp;gt;= "1apr&amp;amp;year."d or end_date = .) then 
     output sub&amp;amp;year
   ;
%end;

RUN;
%mend get;

%get(start=2002,stop=2014,inputds=mydata);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 Nov 2015 23:21:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Symput-to-create-a-macro-variable/m-p/234734#M5936</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2015-11-13T23:21:21Z</dc:date>
    </item>
    <item>
      <title>Re: Symput to create a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Symput-to-create-a-macro-variable/m-p/234735#M5937</link>
      <description>This is essentially this problem:&lt;BR /&gt;&lt;A href="http://www.sascommunity.org/wiki/Split_Data_into_Subsets" target="_blank"&gt;http://www.sascommunity.org/wiki/Split_Data_into_Subsets&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;With the general consensus being - Don't do it &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Fri, 13 Nov 2015 23:20:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Symput-to-create-a-macro-variable/m-p/234735#M5937</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-11-13T23:20:57Z</dc:date>
    </item>
    <item>
      <title>Re: Symput to create a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Symput-to-create-a-macro-variable/m-p/234736#M5938</link>
      <description>&lt;P&gt;Thanks. Saved the suggestions and will apply.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW it's such a great community to get help and response so quickly!&lt;/P&gt;</description>
      <pubDate>Fri, 13 Nov 2015 23:23:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Symput-to-create-a-macro-variable/m-p/234736#M5938</guid>
      <dc:creator>Solph</dc:creator>
      <dc:date>2015-11-13T23:23:15Z</dc:date>
    </item>
    <item>
      <title>Re: Symput to create a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Symput-to-create-a-macro-variable/m-p/234737#M5939</link>
      <description>&lt;P&gt;Thanks. I understood the reasoning and generally I won't do it either. It's a special case that calls for it.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Nov 2015 23:27:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Symput-to-create-a-macro-variable/m-p/234737#M5939</guid>
      <dc:creator>Solph</dc:creator>
      <dc:date>2015-11-13T23:27:33Z</dc:date>
    </item>
  </channel>
</rss>

