<?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: Pulling Dates from Variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Pulling-Dates-from-Variables/m-p/508672#M136647</link>
    <description>&lt;P&gt;I think you may get away with something like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data org;
  set infl.arc_inflation_jb_102618;
  array Pre_ResYr Pre_ResYr:;
  do _N_=1 to dim(Pre_ResYr);
    name=upcase(vname(Pre_ResYr(_N_)));
    select(substr(scan(name,1,'_'),10);
      when('1STM') month=1;
      when('2NDM') month=2;
      /* etcetera */
      otherwise month=0; /* for the stuff that you do not want */
      end;
   if month&amp;gt;0 then do;
      Value=Pre_ResYr(_N_);
      category=scan(name,2,'_');
      output;
      end;
   end;
  keep /* key variables here! */ month value category;
run;
 &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;You can then (if you want to) use PROC TRANSPOSE to create variable names from the CATEGORY variable.&lt;/P&gt;</description>
    <pubDate>Tue, 30 Oct 2018 13:04:30 GMT</pubDate>
    <dc:creator>s_lassen</dc:creator>
    <dc:date>2018-10-30T13:04:30Z</dc:date>
    <item>
      <title>Pulling Dates from Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pulling-Dates-from-Variables/m-p/508469#M136562</link>
      <description>&lt;P&gt;As suggested by Reeza, I am trying to reorganize my data into a long structure opposed to wide to reduce processing time as well as make the coding faster.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Currently, the data is organized a structure where&amp;nbsp;it has main variables such as Recreation, Financial Plan, Legal, Housing, Gift, Education. However, these variables were created in a way that works like Pre_ResYr6thM_Recre and so forth.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am looking for some sample code to pull the "Pre_ResYr&lt;STRONG&gt;N&lt;/STRONG&gt;thM" part from each variable to make a several new variables for the Month, Quarter, Half Year and Year as well as variables for Recreation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried something to the effect of :&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Org;
set infl.arc_inflation_jb_102618;
if Preresyr1stM: then Month = 1;
else if Preresyr2ndM: then Month = 2;
else if Preresyr3rdM: then Month = 3;
else if Preresyr4thM: then Month =4;
else if Preresyr5thM: then Month =5;
else if Preresyr6thM: then Month =6;
else if Preresyr7thM: then Month =7;
else if Preresyr8thM: then Month =8;
else if Preresyr9thM: then Month =9;
else if Preresyr10thM: then Month =10;
else if Preresyr11thM: then Month =11;
else if Preresyr12thM: then Month =12;
run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was then going to just keep the main variables and have a structure like&lt;/P&gt;&lt;P&gt;StudyNo PID Day_1826 Day_InitialIW Month Quarter Half_year PreRes_Consume PreRes_COnsume_Total PostRes_Consume&lt;BR /&gt;PostRes_Consume_Total PreRes_Durable PreRes_Durable_Total&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 1 30Dec1992 05Oct1993 1 1 1 600 600&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 1 30Dec1992 05Oct1993 2 1 1 600 1200&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was hoping to find some sample code or an old forum for the code but not sure how to pull main character strings from the variables to create the new variables&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also tried an iteration that looked like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Org;
set infl.arc_inflation_jb_102618;
if var like %Preresyr1stM% then Month = 1;
.
.
.
.

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 29 Oct 2018 19:04:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pulling-Dates-from-Variables/m-p/508469#M136562</guid>
      <dc:creator>joebacon</dc:creator>
      <dc:date>2018-10-29T19:04:13Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling Dates from Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pulling-Dates-from-Variables/m-p/508480#M136564</link>
      <description>&lt;P&gt;could you try something using the substr function?&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;here would be a start:&lt;/P&gt;&lt;P&gt;var2 = substr(var1, 9, length(var1)-12)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the 9th character is where the month begins... and then you want to count for the length of your variable (var1 in this case) minus the length of the unnecessary characters (the first 9 and the last3).&amp;nbsp; &amp;nbsp;i hope this helps give you some direction.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Oct 2018 19:27:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pulling-Dates-from-Variables/m-p/508480#M136564</guid>
      <dc:creator>utrocketeng</dc:creator>
      <dc:date>2018-10-29T19:27:30Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling Dates from Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pulling-Dates-from-Variables/m-p/508481#M136565</link>
      <description>Since it's the only number in the variable you could just COMPRESS() out all letters and then use INPUT() to convert it to a number.&lt;BR /&gt;&lt;BR /&gt;x = input(compress(var, , 'kd'), 8.);</description>
      <pubDate>Mon, 29 Oct 2018 19:29:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pulling-Dates-from-Variables/m-p/508481#M136565</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-10-29T19:29:15Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling Dates from Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pulling-Dates-from-Variables/m-p/508483#M136566</link>
      <description>&lt;P&gt;that is cool, i need to remember this for the future.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Oct 2018 19:30:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pulling-Dates-from-Variables/m-p/508483#M136566</guid>
      <dc:creator>utrocketeng</dc:creator>
      <dc:date>2018-10-29T19:30:43Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling Dates from Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pulling-Dates-from-Variables/m-p/508484#M136567</link>
      <description>&lt;P&gt;Actually what you should do there is an array approach.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;

array _month(12) &amp;lt;list of variables in order&amp;gt;;

do i=1 to dim(_month);
    interval='Month';
    Period = i;
    Value = _month(i);
     output;
end;

run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 29 Oct 2018 19:31:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pulling-Dates-from-Variables/m-p/508484#M136567</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-10-29T19:31:16Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling Dates from Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pulling-Dates-from-Variables/m-p/508672#M136647</link>
      <description>&lt;P&gt;I think you may get away with something like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data org;
  set infl.arc_inflation_jb_102618;
  array Pre_ResYr Pre_ResYr:;
  do _N_=1 to dim(Pre_ResYr);
    name=upcase(vname(Pre_ResYr(_N_)));
    select(substr(scan(name,1,'_'),10);
      when('1STM') month=1;
      when('2NDM') month=2;
      /* etcetera */
      otherwise month=0; /* for the stuff that you do not want */
      end;
   if month&amp;gt;0 then do;
      Value=Pre_ResYr(_N_);
      category=scan(name,2,'_');
      output;
      end;
   end;
  keep /* key variables here! */ month value category;
run;
 &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;You can then (if you want to) use PROC TRANSPOSE to create variable names from the CATEGORY variable.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Oct 2018 13:04:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pulling-Dates-from-Variables/m-p/508672#M136647</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2018-10-30T13:04:30Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling Dates from Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pulling-Dates-from-Variables/m-p/508702#M136666</link>
      <description>&lt;P&gt;This seems to be working well, except I have a few questions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First, the first month value is being doubled and the last is being taken away. Could this be because the DO Loop is stopping at 11 and not 12?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Secondly, when I run a second array, how would I keep the previous column while generating a new one?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Obviously, I have never really used arrays. I appreciate all your help, I am trying to learn as much as possible in a short time and you've been very patient.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Tall;
set infl.arc_inflation_jb_102618;
array _month(12) N_PreResYr1stM_House
N_PreResYr2ndM_House
N_PreResYr3rdM_House
N_PreResYr4thM_House
N_PreResYr5thM_House
N_PreResYr6thM_House
N_PreResYr7thM_House
N_PreResYr8thM_House
N_PreResYr9thM_House
N_PreResYr10thM_House
N_PreResYr11thM_House
N_PreResYr12thM_House
;

do i=1 to dim(_month);
    interval='Month';
    Month = i;
    PreResYr_House = _month(i);
     output;
end;

run;


 
data Tall;
set infl.arc_inflation_jb_102618;
array _month(12) N_PreResYr1stM_CONSUME
N_PreResYr2ndM_CONSUME
N_PreResYr3rdM_CONSUME
N_PreResYr4thM_CONSUME
N_PreResYr5thM_CONSUME
N_PreResYr6thM_CONSUME
N_PreResYr7thM_CONSUME
N_PreResYr8thM_CONSUME
N_PreResYr9thM_CONSUME
N_PreResYr10thM_CONSUME
N_PreResYr11thM_CONSUME
N_PreResYr12thM_CONSUME;

do i=1 to dim(_month);
    interval='Month';
    Month = i;
    PreResYr_CONSUME = _month(i);
     output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This code generates just the PreResYr_Consume without the PreResYr_House and it also doubles the first month value as seen below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i&amp;nbsp; Interval Month PreResYr_Consume&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; Month 1 767.101074&lt;BR /&gt;2 Month 2 383.550537&lt;BR /&gt;3 Month 3 383.550537&lt;BR /&gt;4 Month 4 383.550537&lt;BR /&gt;5 Month 5 383.550537&lt;BR /&gt;6 Month 6 383.550537&lt;BR /&gt;7 Month 7 383.550537&lt;BR /&gt;8 Month 8 383.550537&lt;BR /&gt;9 Month 9 383.550537&lt;BR /&gt;10 Month 10 383.550537&lt;BR /&gt;11 Month 11 383.550537&lt;BR /&gt;12 Month 12 .&lt;/P&gt;</description>
      <pubDate>Tue, 30 Oct 2018 14:17:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pulling-Dates-from-Variables/m-p/508702#M136666</guid>
      <dc:creator>joebacon</dc:creator>
      <dc:date>2018-10-30T14:17:55Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling Dates from Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pulling-Dates-from-Variables/m-p/508704#M136668</link>
      <description>&lt;P&gt;Also, this is really cool. Good tip and bookmarked.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Oct 2018 14:18:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pulling-Dates-from-Variables/m-p/508704#M136668</guid>
      <dc:creator>joebacon</dc:creator>
      <dc:date>2018-10-30T14:18:41Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling Dates from Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pulling-Dates-from-Variables/m-p/508722#M136678</link>
      <description>&lt;P&gt;You can have multiple arrays and steps in one data step. In fact, I think you'll have to here otherwise you're going to get weird results.&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;PRE&gt;&lt;CODE class=" language-sas"&gt;
data Tall;
set infl.arc_inflation_jb_102618;
array _month(12) N_PreResYr1stM_House
N_PreResYr2ndM_House
N_PreResYr3rdM_House
N_PreResYr4thM_House
N_PreResYr5thM_House
N_PreResYr6thM_House
N_PreResYr7thM_House
N_PreResYr8thM_House
N_PreResYr9thM_House
N_PreResYr10thM_House
N_PreResYr11thM_House
N_PreResYr12thM_House
;

do i=1 to dim(_month);
    interval='Month';
    Month = i;
    PreResYr_House = _month(i);
     output;
end;


array _month(12) N_PreResYr1stM_CONSUME
N_PreResYr2ndM_CONSUME
N_PreResYr3rdM_CONSUME
N_PreResYr4thM_CONSUME
N_PreResYr5thM_CONSUME
N_PreResYr6thM_CONSUME
N_PreResYr7thM_CONSUME
N_PreResYr8thM_CONSUME
N_PreResYr9thM_CONSUME
N_PreResYr10thM_CONSUME
N_PreResYr11thM_CONSUME
N_PreResYr12thM_CONSUME;

do i=1 to dim(_month);
    interval='Month';
    Month = i;
    PreResYr_CONSUME = _month(i);
     output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/241893"&gt;@joebacon&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;This seems to be working well, except I have a few questions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First, the first month value is being doubled and the last is being taken away. Could this be because the DO Loop is stopping at 11 and not 12?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Secondly, when I run a second array, how would I keep the previous column while generating a new one?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Obviously, I have never really used arrays. I appreciate all your help, I am trying to learn as much as possible in a short time and you've been very patient.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Tall;
set infl.arc_inflation_jb_102618;
array _month(12) N_PreResYr1stM_House
N_PreResYr2ndM_House
N_PreResYr3rdM_House
N_PreResYr4thM_House
N_PreResYr5thM_House
N_PreResYr6thM_House
N_PreResYr7thM_House
N_PreResYr8thM_House
N_PreResYr9thM_House
N_PreResYr10thM_House
N_PreResYr11thM_House
N_PreResYr12thM_House
;

do i=1 to dim(_month);
    interval='Month';
    Month = i;
    PreResYr_House = _month(i);
     output;
end;

run;


 
data Tall;
set infl.arc_inflation_jb_102618;
array _month(12) N_PreResYr1stM_CONSUME
N_PreResYr2ndM_CONSUME
N_PreResYr3rdM_CONSUME
N_PreResYr4thM_CONSUME
N_PreResYr5thM_CONSUME
N_PreResYr6thM_CONSUME
N_PreResYr7thM_CONSUME
N_PreResYr8thM_CONSUME
N_PreResYr9thM_CONSUME
N_PreResYr10thM_CONSUME
N_PreResYr11thM_CONSUME
N_PreResYr12thM_CONSUME;

do i=1 to dim(_month);
    interval='Month';
    Month = i;
    PreResYr_CONSUME = _month(i);
     output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This code generates just the PreResYr_Consume without the PreResYr_House and it also doubles the first month value as seen below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;i&amp;nbsp; Interval Month PreResYr_Consume&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; Month 1 767.101074&lt;BR /&gt;2 Month 2 383.550537&lt;BR /&gt;3 Month 3 383.550537&lt;BR /&gt;4 Month 4 383.550537&lt;BR /&gt;5 Month 5 383.550537&lt;BR /&gt;6 Month 6 383.550537&lt;BR /&gt;7 Month 7 383.550537&lt;BR /&gt;8 Month 8 383.550537&lt;BR /&gt;9 Month 9 383.550537&lt;BR /&gt;10 Month 10 383.550537&lt;BR /&gt;11 Month 11 383.550537&lt;BR /&gt;12 Month 12 .&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Oct 2018 14:51:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pulling-Dates-from-Variables/m-p/508722#M136678</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-10-30T14:51:48Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling Dates from Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pulling-Dates-from-Variables/m-p/508735#M136682</link>
      <description>&lt;P&gt;I then get the error that _month has already been defined.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;44 end;&lt;BR /&gt;45&lt;BR /&gt;46&lt;BR /&gt;47 array _month(12) N_PreResYr1stM_CONSUME&lt;BR /&gt;______&lt;BR /&gt;124&lt;BR /&gt;ERROR 124-185: The variable _month has already been defined.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I want the months to stay but to input the value for each month under the new Consume category as well.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Oct 2018 15:02:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pulling-Dates-from-Variables/m-p/508735#M136682</guid>
      <dc:creator>joebacon</dc:creator>
      <dc:date>2018-10-30T15:02:03Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling Dates from Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pulling-Dates-from-Variables/m-p/508738#M136683</link>
      <description>&lt;P&gt;I'm a dummy. I just need to use the months and create the new variables in an If when statement. Sorry.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Oct 2018 15:05:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pulling-Dates-from-Variables/m-p/508738#M136683</guid>
      <dc:creator>joebacon</dc:creator>
      <dc:date>2018-10-30T15:05:03Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling Dates from Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pulling-Dates-from-Variables/m-p/508786#M136689</link>
      <description>&lt;P&gt;Reeza, I apologize for all the questions, but could you point me to where my Macro went wrong?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%Macro Transform(x);
When(&amp;amp;x.) do;
PreResYr_Consume =N_PreResYr&amp;amp;x.thM_CONSUME;
PreResYr_Durable =N_PreResYr&amp;amp;x.thM_DURABLE;
PreResYr_Trans =N_PreResYr&amp;amp;x.thM_TRANS;
PreResYr_Health =N_PreResYr&amp;amp;x.thM_HEALTH;
PreResYr_Insure =N_PreResYr&amp;amp;x.thM_INSURE;
PreResYr_Loan =N_PreResYr&amp;amp;x.thM_LOAN;
PreResYr_Tax =N_PreResYr&amp;amp;x.thM_TAX;
PreResYr_Educa =N_PreResYr&amp;amp;x.thM_EDUCA;
PreResYr_Gift =N_PreResYr&amp;amp;x.thM_GIFT;
PreResYr_Enter =N_PreResYr&amp;amp;x.thM_ENTER;
PreResYr_Recre =N_PreResYr&amp;amp;x.thM_RECRE;
PreResYr_Finplan =N_PreResYr&amp;amp;x.thM_FINPLAN;
PreResYr_Legala =N_PreResYr&amp;amp;x.thM_LEGALA;
PreResYr_IncomeTL =N_PreResYr&amp;amp;x.thM_INCOMETL;
end;
%Mend Transform;
data Tall2;
set Tall;
Select(Month);
When(1) do;
PreResYr_Consume =N_PreResYr1stM_CONSUME;
PreResYr_Durable =N_PreResYr1stM_DURABLE;
PreResYr_Trans =N_PreResYr1stM_TRANS;
PreResYr_Health =N_PreResYr1stM_HEALTH;
PreResYr_Insure =N_PreResYr1stM_INSURE;
PreResYr_Loan =N_PreResYr1stM_LOAN;
PreResYr_Tax =N_PreResYr1stM_TAX;
PreResYr_Educa =N_PreResYr1stM_EDUCA;
PreResYr_Gift =N_PreResYr1stM_GIFT;
PreResYr_Enter =N_PreResYr1stM_ENTER;
PreResYr_Recre =N_PreResYr1stM_RECRE;
PreResYr_Finplan =N_PreResYr1stM_FINPLAN;
PreResYr_Legala =N_PreResYr1stM_LEGALA;
PreResYr_IncomeTL =N_PreResYr1stM_INCOMETL;
end;
When(2) do;
PreResYr_Consume =N_PreResYr2ndM_CONSUME;
PreResYr_Durable =N_PreResYr2ndM_DURABLE;
PreResYr_Trans =N_PreResYr2ndM_TRANS;
PreResYr_Health =N_PreResYr2ndM_HEALTH;
PreResYr_Insure =N_PreResYr2ndM_INSURE;
PreResYr_Loan =N_PreResYr2ndM_LOAN;
PreResYr_Tax =N_PreResYr2ndM_TAX;
PreResYr_Educa =N_PreResYr2ndM_EDUCA;
PreResYr_Gift =N_PreResYr2ndM_GIFT;
PreResYr_Enter =N_PreResYr2ndM_ENTER;
PreResYr_Recre =N_PreResYr2ndM_RECRE;
PreResYr_Finplan =N_PreResYr2ndM_FINPLAN;
PreResYr_Legala =N_PreResYr2ndM_LEGALA;
PreResYr_IncomeTL =N_PreResYr2ndM_INCOMETL;
end;
When(3) do;
PreResYr_Consume =N_PreResYr3rdM_CONSUME;
PreResYr_Durable =N_PreResYr3rdM_DURABLE;
PreResYr_Trans =N_PreResYr3rdM_TRANS;
PreResYr_Health =N_PreResYr3rdM_HEALTH;
PreResYr_Insure =N_PreResYr3rdM_INSURE;
PreResYr_Loan =N_PreResYr3rdM_LOAN;
PreResYr_Tax =N_PreResYr3rdM_TAX;
PreResYr_Educa =N_PreResYr3rdM_EDUCA;
PreResYr_Gift =N_PreResYr3rdM_GIFT;
PreResYr_Enter =N_PreResYr3rdM_ENTER;
PreResYr_Recre =N_PreResYr3rdM_RECRE;
PreResYr_Finplan =N_PreResYr3rdM_FINPLAN;
PreResYr_Legala =N_PreResYr3rdM_LEGALA;
PreResYr_IncomeTL =N_PreResYr3rdM_INCOMETL;
end;
%Transform(4-11);

Otherwise do;
PreResYr_Consume =N_PreResYr12thM_CONSUME;
PreResYr_Durable =N_PreResYr12thM_DURABLE;
PreResYr_Trans =N_PreResYr12thM_TRANS;
PreResYr_Health =N_PreResYr12thM_HEALTH;
PreResYr_Insure =N_PreResYr12thM_INSURE;
PreResYr_Loan =N_PreResYr12thM_LOAN;
PreResYr_Tax =N_PreResYr12thM_TAX;
PreResYr_Educa =N_PreResYr12thM_EDUCA;
PreResYr_Gift =N_PreResYr12thM_GIFT;
PreResYr_Enter =N_PreResYr12thM_ENTER;
PreResYr_Recre =N_PreResYr12thM_RECRE;
PreResYr_Finplan =N_PreResYr12thM_FINPLAN;
PreResYr_Legala =N_PreResYr12thM_LEGALA;
PreResYr_IncomeTL =N_PreResYr12thM_INCOMETL;
end;

run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Can I not do a range from 4-11? I am getting 3 errors but i specified an "when" and "end" statement in the macro and the otherwise do is in context to the previous "select" :&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOTE: Line generated by the macro variable "X".
92         N_PreResYr4-11thM_INCOMETL
                         ____________
                         22
ERROR: Expecting "WHEN", "OTHERWISE", or "END".
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, *, **, +, -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;&amp;lt;, &amp;gt;=, AND, EQ, GE, GT, IN, 
              LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, ^=, |, ||, ~=.  

93         end;
94         Otherwise do;
           _________
           161
ERROR 161-185: No matching DO/SELECT statement.&lt;/CODE&gt;&lt;/PRE&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;</description>
      <pubDate>Tue, 30 Oct 2018 16:05:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pulling-Dates-from-Variables/m-p/508786#M136689</guid>
      <dc:creator>joebacon</dc:creator>
      <dc:date>2018-10-30T16:05:06Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling Dates from Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pulling-Dates-from-Variables/m-p/508796#M136692</link>
      <description>%Transform(4-11); *this is wrong. You cannot call it like that. It's literal text replacement and you have no loop so it's not looping. 4-11 gets replaced everywhere you have the macro variable and that's not what you want. There's no loop code that I see. &lt;BR /&gt;&lt;BR /&gt;To write a macro, first ensure it works in a base case, then start adding macro variables and loops.&lt;BR /&gt;&lt;BR /&gt;I wrote a short tutorial here, let me know if it helps. This assumes you start with working code though.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md" target="_blank"&gt;https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 30 Oct 2018 16:20:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pulling-Dates-from-Variables/m-p/508796#M136692</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-10-30T16:20:47Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling Dates from Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pulling-Dates-from-Variables/m-p/508814#M136693</link>
      <description>&lt;P&gt;Once more, I can't thank you enough! This is so helpful - clear, simple, and informative.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Oct 2018 16:45:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pulling-Dates-from-Variables/m-p/508814#M136693</guid>
      <dc:creator>joebacon</dc:creator>
      <dc:date>2018-10-30T16:45:21Z</dc:date>
    </item>
  </channel>
</rss>

