<?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: Generate strings using macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Generate-strings-using-macro/m-p/314612#M68554</link>
    <description>&lt;P&gt;It would seem to me that you should just skip the PROC IMPORT and just read your data file directly.&lt;/P&gt;
&lt;P&gt;Can you explain the data structure in more detail?&lt;/P&gt;
&lt;P&gt;So column 22 has the date? And column 24 onward are values for follow-up dates that are based on that starting date? &amp;nbsp;Does that extend to the end of the line?&lt;/P&gt;
&lt;P&gt;What do the first 21 columns contain?&lt;/P&gt;
&lt;P&gt;What does column 23 contain?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What happens on the next observation? &amp;nbsp;Is column 22 the same for every row in the source file? &amp;nbsp;If not then your RENAME method is bound to fail.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What structure would you like for the data? &amp;nbsp;I would assume that it would make much more sense to have a series of observations with DATE/VALUE pairs instead of putting the date information into the NAME of the variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How are you going to use the data?&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;</description>
    <pubDate>Sun, 27 Nov 2016 16:43:18 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2016-11-27T16:43:18Z</dc:date>
    <item>
      <title>Generate strings using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-strings-using-macro/m-p/311236#M67208</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I am stuck into some real time situation, every month I get a notepad file without headers and I do use proc import to get the data in SAS dataset. Now in this notepad there are so many fields(aprox 500) so proc import give the variable names as Var1 Var2 ...Var500&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So once I have created the dataset , now I rename the variables starting from var24.&lt;/P&gt;
&lt;P&gt;so the pattern is somehting like in one varibale lets say in var22 I get a date, lets say it start date then I need to trac data for 24 months back.&lt;/P&gt;
&lt;P&gt;Example- lets say in var22 I have date - 13-Oct-2016&lt;/P&gt;
&lt;P&gt;now I will rename the vars starting from var24 like this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Rename(&lt;/P&gt;
&lt;P&gt;var24=V_10_13_2016&lt;/P&gt;
&lt;P&gt;Var25=V_10_06_2016&lt;/P&gt;
&lt;P&gt;Var26=V_09_30_2016&lt;/P&gt;
&lt;P&gt;Var27=V_09_23_2016&lt;/P&gt;
&lt;P&gt;Var28=V_09_16_2016&lt;/P&gt;
&lt;P&gt;Var27=V_09_09_2016&lt;/P&gt;
&lt;P&gt;...................................&lt;/P&gt;
&lt;P&gt;till 24 months.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now if you see the pattern we go back 7 days but if that changes the month then we stop at the last day of the month, see above&lt;/P&gt;
&lt;P&gt;Var25=V_10_06_2016&lt;/P&gt;
&lt;P&gt;Var26=V_09_30_2016&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now If I can write a macro to create such string&amp;nbsp;&lt;SPAN&gt;Var27=V_09_09_2016 like this then my task will be easy and I can redduce my work hrs.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Please help me in here. Thanks&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 13 Nov 2016 11:39:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-strings-using-macro/m-p/311236#M67208</guid>
      <dc:creator>LittlesasMaster</dc:creator>
      <dc:date>2016-11-13T11:39:33Z</dc:date>
    </item>
    <item>
      <title>Re: Generate strings using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-strings-using-macro/m-p/311277#M67233</link>
      <description>&lt;P&gt;Adapt next macro/code to your needs:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro ren_vars(v2start=24, 
                v2end=40,    
                from_date=13-Oct-2016);
    data _null_;
       length ren_all $10000 renx $25 datex $10;
       datex = compress("&amp;amp;from_date",'-')||'d';
       from_date = input(datex,date9.); *put from_date=;
       vnum = &amp;amp;v2start;
       varx = "var&amp;amp;v2start";
       
       do until (vnum = &amp;amp;v2end);
          datex = put(from_date,mmddyy10.);
          renx  = cat(varx,' = ',"v_",datex); *put renx=;
          ren_all = trim(ren_all) ||' '|| renx;
          if day(from_date) &amp;gt; 7 then from_date = from_date - 7;
          else from_date = intnx('month',from_date,-1,'e');
          vnum+1;
       end;
       call symput('ren_all',trim(ren_all));
   run;
   %put ren_all=&amp;amp;ren_all;   /* check results in the log */
%mend ren_vars;
%ren_vars(v2start=24, 
          v2end=40,     /* addapt to needs, 500 ? */
          from_date=13-Oct-2016);
             &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 13 Nov 2016 20:23:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-strings-using-macro/m-p/311277#M67233</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-11-13T20:23:35Z</dc:date>
    </item>
    <item>
      <title>Re: Generate strings using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-strings-using-macro/m-p/311286#M67239</link>
      <description>&lt;P&gt;I feel that instead of creating logic to rename the variables, you should be trying to come up/ask for logic to transpose your data from a wide into a long structure. That could make things quite a bit easier.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It would also help a lot if you could post some representative sample data.&lt;/P&gt;</description>
      <pubDate>Sun, 13 Nov 2016 21:48:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-strings-using-macro/m-p/311286#M67239</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2016-11-13T21:48:21Z</dc:date>
    </item>
    <item>
      <title>Re: Generate strings using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-strings-using-macro/m-p/311377#M67279</link>
      <description>&lt;P&gt;If the file is &lt;STRONG&gt;supposed&lt;/STRONG&gt; to be in the same format then you should only use proc import one time. Proc import when reading text files will create data step code to read the file. Look in the log after importing one of these files to see the code. Copy it from the Log to an editor and make needed changes such as specifying the variable names, double checking on informats to maintain consistent types and lengths of character variables and possibly adding labels. Then you only need to change the name of the input file and output data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you continually use Proc Import you will with very high probability end up with variables of different types, numeric and text, or different length character variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the file format changes then it still may be easier to create incremented code to read the desired variables it just adds a step for you to tell the program the start end dates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that if the data was actually in long form:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Date Value instead of having a separate column for each value the data would be much easier to handle in the long run.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Nov 2016 11:51:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-strings-using-macro/m-p/311377#M67279</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-11-14T11:51:34Z</dc:date>
    </item>
    <item>
      <title>Re: Generate strings using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-strings-using-macro/m-p/311781#M67477</link>
      <description>&lt;P&gt;So here is what i do everyday.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Firrt run Proc Import and get the text file in SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc import datafile="File.txt" out=mydataset&lt;/P&gt;
&lt;P&gt;dbms=dlm replace;&lt;/P&gt;
&lt;P&gt;delimiter=";";&lt;/P&gt;
&lt;P&gt;getnames=no;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data want;&lt;/P&gt;
&lt;P&gt;set mydataset(rename=&lt;/P&gt;
&lt;P&gt;(&lt;/P&gt;
&lt;P&gt;ar24=V_10_13_2016&lt;/P&gt;
&lt;P&gt;Var25=V_10_06_2016&lt;/P&gt;
&lt;P&gt;Var26=V_09_30_2016&lt;/P&gt;
&lt;P&gt;Var27=V_09_23_2016&lt;/P&gt;
&lt;P&gt;Var28=V_09_16_2016&lt;/P&gt;
&lt;P&gt;Var27=V_09_09_2016&lt;/P&gt;
&lt;P&gt;/*for all 500 vars */)&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;now want data is ready for me to work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I was trying to create a macro so that I can replace that I can call my macro&lt;/P&gt;
&lt;P&gt;rename=(%mymacro);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please help me in here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2016 17:11:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-strings-using-macro/m-p/311781#M67477</guid>
      <dc:creator>LittlesasMaster</dc:creator>
      <dc:date>2016-11-15T17:11:40Z</dc:date>
    </item>
    <item>
      <title>Re: Generate strings using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-strings-using-macro/m-p/311841#M67509</link>
      <description>&lt;P&gt;I posted you such macro name &lt;STRONG&gt;REN_VARS&lt;/STRONG&gt; geting 3 arguments:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;(1) &amp;nbsp;&lt;STRONG&gt;v2start = 24 &lt;/STRONG&gt;as you wanted to rename from &lt;STRONG&gt;var24&lt;/STRONG&gt; on&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;(2) &amp;nbsp;&lt;STRONG&gt;v2end &amp;nbsp; = 40&lt;/STRONG&gt; as you said that your last var to rename is&lt;STRONG&gt; var40&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;(3) &lt;STRONG&gt;from_date = 13-OCT-2016&lt;/STRONG&gt; as you computed dates startin with OCT 13th, 2016&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;going backwards (to the past) decresing 7 days except when mont changes then last day in month.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The macro&amp;nbsp;&lt;STRONG&gt;REN_VARS&lt;/STRONG&gt; creates a string like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;SPAN&gt;var&lt;STRONG&gt;24&lt;/STRONG&gt;=V_&lt;STRONG&gt;10_13&lt;/STRONG&gt;_2016 &amp;nbsp;var&lt;STRONG&gt;25&lt;/STRONG&gt;=V_&lt;STRONG&gt;10_06&lt;/STRONG&gt;_2016 &amp;nbsp;var&lt;STRONG&gt;26&lt;/STRONG&gt;=V_&lt;STRONG&gt;09_30&lt;/STRONG&gt;_2016 ... etc&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The result will be in a macro variable named &lt;STRONG&gt;ren_all&amp;nbsp;&lt;/STRONG&gt; to be used as:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;data want;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; set mydataset (rename=( &lt;STRONG&gt;&amp;amp;ren_all)&lt;/STRONG&gt;);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; ...&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2016 20:09:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-strings-using-macro/m-p/311841#M67509</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-11-15T20:09:27Z</dc:date>
    </item>
    <item>
      <title>Re: Generate strings using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-strings-using-macro/m-p/313548#M68149</link>
      <description>&lt;P style="margin: 0in; margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica','sans-serif'; color: #333333;"&gt;Thanks&amp;nbsp;&lt;SPAN class="login-bold"&gt;&lt;A id="link_8" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384" target="_self"&gt;Shmuel&lt;/A&gt;, this is what I was looking towards, I am working on your code to make it work for me for all&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0in; margin-bottom: .0001pt; font-variant-ligatures: normal; font-variant-caps: normal; orphans: 2; text-align: start; widows: 2; -webkit-text-stroke-width: 0px; word-spacing: 0px;"&gt;&lt;SPAN class="login-bold"&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica','sans-serif'; color: #333333;"&gt;rest of the vars.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0in; margin-bottom: .0001pt; font-variant-ligatures: normal; font-variant-caps: normal; orphans: 2; text-align: start; widows: 2; -webkit-text-stroke-width: 0px; word-spacing: 0px;"&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica','sans-serif'; color: #333333;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0in; margin-bottom: .0001pt; font-variant-ligatures: normal; font-variant-caps: normal; orphans: 2; text-align: start; widows: 2; -webkit-text-stroke-width: 0px; word-spacing: 0px;"&gt;&lt;SPAN class="login-bold"&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica','sans-serif'; color: #333333;"&gt;your help highly appreciated.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2016 18:10:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-strings-using-macro/m-p/313548#M68149</guid>
      <dc:creator>LittlesasMaster</dc:creator>
      <dc:date>2016-11-22T18:10:52Z</dc:date>
    </item>
    <item>
      <title>Re: Generate strings using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-strings-using-macro/m-p/314611#M68553</link>
      <description>&lt;P style="margin: 0in; margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica','sans-serif'; color: #333333;"&gt;Hi&amp;nbsp;&lt;A id="link_8" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384" target="_self"&gt;Shmuel&lt;/A&gt;,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0in; margin-bottom: .0001pt; font-variant-ligatures: normal; font-variant-caps: normal; orphans: 2; text-align: start; widows: 2; -webkit-text-stroke-width: 0px; word-spacing: 0px;"&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica','sans-serif'; color: #333333;"&gt;I am trying to run your code and the result I am getting is like this&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0in; margin-bottom: .0001pt; font-variant-ligatures: normal; font-variant-caps: normal; orphans: 2; text-align: start; widows: 2; -webkit-text-stroke-width: 0px; word-spacing: 0px;"&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica','sans-serif'; color: #333333;"&gt;var24 = v_10/13/2016 var24 = v_10/06/2016 var24 = v_09/30/2016 var24 = v_09/23/2016......&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0in; margin-bottom: .0001pt; font-variant-ligatures: normal; font-variant-caps: normal; orphans: 2; text-align: start; widows: 2; -webkit-text-stroke-width: 0px; word-spacing: 0px;"&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica','sans-serif'; color: #333333;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0in; margin-bottom: .0001pt; font-variant-ligatures: normal; font-variant-caps: normal; orphans: 2; text-align: start; widows: 2; -webkit-text-stroke-width: 0px; word-spacing: 0px;"&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica','sans-serif'; color: #333333;"&gt;but if you see var24 is costant and date should be in underscore separated not by '/';&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0in; margin-bottom: .0001pt; font-variant-ligatures: normal; font-variant-caps: normal; orphans: 2; text-align: start; widows: 2; -webkit-text-stroke-width: 0px; word-spacing: 0px;"&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica','sans-serif'; color: #333333;"&gt;so desired output should be like this&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0in; margin-bottom: .0001pt; font-variant-ligatures: normal; font-variant-caps: normal; orphans: 2; text-align: start; widows: 2; -webkit-text-stroke-width: 0px; word-spacing: 0px;"&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica','sans-serif'; color: #333333;"&gt;var24 = v_10_13_2016 var25 = v_10_06_2016 var26 = v_09_30_2016 var27 = v_09_23_2016....&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0in; margin-bottom: .0001pt; font-variant-ligatures: normal; font-variant-caps: normal; orphans: 2; text-align: start; widows: 2; -webkit-text-stroke-width: 0px; word-spacing: 0px;"&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica','sans-serif'; color: #333333;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0in; margin-bottom: .0001pt; font-variant-ligatures: normal; font-variant-caps: normal; orphans: 2; text-align: start; widows: 2; -webkit-text-stroke-width: 0px; word-spacing: 0px;"&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica','sans-serif'; color: #333333;"&gt;Please help me in here.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0in; margin-bottom: .0001pt; font-variant-ligatures: normal; font-variant-caps: normal; orphans: 2; text-align: start; widows: 2; -webkit-text-stroke-width: 0px; word-spacing: 0px;"&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica','sans-serif'; color: #333333;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0in; margin-bottom: .0001pt; font-variant-ligatures: normal; font-variant-caps: normal; orphans: 2; text-align: start; widows: 2; -webkit-text-stroke-width: 0px; word-spacing: 0px;"&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica','sans-serif'; color: #333333;"&gt;Thanks&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 27 Nov 2016 16:17:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-strings-using-macro/m-p/314611#M68553</guid>
      <dc:creator>LittlesasMaster</dc:creator>
      <dc:date>2016-11-27T16:17:12Z</dc:date>
    </item>
    <item>
      <title>Re: Generate strings using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-strings-using-macro/m-p/314612#M68554</link>
      <description>&lt;P&gt;It would seem to me that you should just skip the PROC IMPORT and just read your data file directly.&lt;/P&gt;
&lt;P&gt;Can you explain the data structure in more detail?&lt;/P&gt;
&lt;P&gt;So column 22 has the date? And column 24 onward are values for follow-up dates that are based on that starting date? &amp;nbsp;Does that extend to the end of the line?&lt;/P&gt;
&lt;P&gt;What do the first 21 columns contain?&lt;/P&gt;
&lt;P&gt;What does column 23 contain?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What happens on the next observation? &amp;nbsp;Is column 22 the same for every row in the source file? &amp;nbsp;If not then your RENAME method is bound to fail.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What structure would you like for the data? &amp;nbsp;I would assume that it would make much more sense to have a series of observations with DATE/VALUE pairs instead of putting the date information into the NAME of the variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How are you going to use the data?&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;</description>
      <pubDate>Sun, 27 Nov 2016 16:43:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-strings-using-macro/m-p/314612#M68554</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-11-27T16:43:18Z</dc:date>
    </item>
    <item>
      <title>Re: Generate strings using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-strings-using-macro/m-p/314614#M68555</link>
      <description>&lt;P&gt;This is going to be much easier to do with a DATA step than macro code.&lt;/P&gt;
&lt;P&gt;Let's make a simple example dataset that has VAR22 and some other variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  var22 = '13oct2016'd ;
  length var24 - var200 8 ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now let's write a DATA _NULL_ step to write out a RENAME statement into a text file. &amp;nbsp;I have adjusted it to use YYYY-MM-DD format instead of MM-DD-YYYY format because then the variable names will sort alphabetically into the proper order.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code temp;
data _null_;
  file code ;
  set have (obs=1 keep= var22);
  put 'rename ' ;
  previous = var22;
  date     = var22;
  format var22 previous date YYMMDD10. ;
  length varname newname $32 ;
  do i=24 by 1  ;
    varname=cats('var',i);
    date = intnx('day',previous,-7);
    if month(date) ^= month(previous) then date=intnx('month',date,0,'end');
    if (date &amp;lt;= intnx('month',var22,-24)) then leave ;
    newname = 'V_' || translate( put(date, yymmdd10.) , '_','-') ;
    put varname '=' newname ;
    previous=date ;
  end;
  put ';' ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you can just %INCLUDE that statement where you need it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set have ;
  %inc code / source2 ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results&lt;/P&gt;
&lt;PRE&gt;106  data want ;
107    set have ;
108    %inc code / source2 ;
NOTE: %INCLUDE (level 1) file CODE is file
      /.../#LN00013.
109 +rename
110 +var24 =V_2016_10_06
111 +var25 =V_2016_09_30
112 +var26 =V_2016_09_23
113 +var27 =V_2016_09_16
114 +var28 =V_2016_09_09
115 +var29 =V_2016_09_02
116 +var30 =V_2016_08_31
117 +var31 =V_2016_08_24
118 +var32 =V_2016_08_17
119 +var33 =V_2016_08_10
120 +var34 =V_2016_08_03
121 +var35 =V_2016_07_31
122 +var36 =V_2016_07_24&lt;/PRE&gt;</description>
      <pubDate>Sun, 27 Nov 2016 17:12:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-strings-using-macro/m-p/314614#M68555</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-11-27T17:12:41Z</dc:date>
    </item>
    <item>
      <title>Re: Generate strings using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-strings-using-macro/m-p/314624#M68557</link>
      <description>&lt;P&gt;Hi Tom,&lt;/P&gt;
&lt;P&gt;I really apriciate your intrest into this so here are the answers of your questions&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Does that extend to the end of the line? &lt;FONT color="#0000FF"&gt;yes from &amp;nbsp;24 to 535 vars&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;set of three group of vars var24 to var151 and var152 to v279 and (next two set of 127 vars in each ).....till 535&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;What do the first 21 columns contain? &amp;nbsp;&lt;FONT color="#0000FF"&gt;these are&amp;nbsp;Client_Number,Report_Number,Prescriber_ID.. etc.... and these are fixed so I can easly rename this and they never change in any file we receive from client.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What does column 23 contain?&amp;nbsp;&lt;FONT color="#0000FF"&gt;Maximum_Number_of_Buckets&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;so data structure is something like&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;var1 to var23 constant var names and from var24 to var 535 each of 127 set of vars&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;will have date values like I said going back 7 days from start date(var22) and if next month then end of month.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;hope this will help&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;thanks!&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 27 Nov 2016 17:26:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-strings-using-macro/m-p/314624#M68557</guid>
      <dc:creator>LittlesasMaster</dc:creator>
      <dc:date>2016-11-27T17:26:42Z</dc:date>
    </item>
    <item>
      <title>Re: Generate strings using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-strings-using-macro/m-p/314626#M68559</link>
      <description>&lt;P&gt;Sounds like you can just write a single data step to read the file.&lt;/P&gt;
&lt;P&gt;The program could look something like this. &amp;nbsp;Fill in the names and types for the rest of the first 23 variables and attach any informats or formats that they need (don't attach formats that they don't need). &amp;nbsp;Make some more meaningful variable names for your three arrays of readings.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  infile 'myfile' dsd dlm=';' truncover ;
  length Client_Number $10
             Report_Number $12 
             ...
             Report_Date 8
             Maximum_Number_of_Buckets 8
  ;
  informat Report_Date date9. ;
  format Report_Date Date date9. ;
  array A (127);
  array B (127);
  array C (127);
  input Client_Number -- Maximum_Number_of_Buckets a1-a127 b1-b127 c1-c127;
  previous = Report_Date ;
  do i=1 to Maximum_Number_of_Buckets ;
     date = intnx('day',previous,-7) ;
     if month(date) ne month(previous) then date=intnx('month',date,0,'end');
     reading1 = a(i);
     reading2 = b(i);
     reading3 = c(i);
     output;
     previous = date;
  end;
  drop a1-a127 b1-b127 c1-c127 previous i ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This is assuming that the values are aligned into the 127 cells. &amp;nbsp;So if there are 3 buckets you have 3 values then 124 empty values then 3 values etc. If instead the empty cells are all at the end so that you have A,A,A,B,B,B,C,C,C,.,.,. then just use one array and calculate where to find the right values.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;     reading1 = a(i);
     reading2 = a(Maximum_Number_of_Buckets + i);
     reading3 = a(2*Maximum_Number_of_Buckets + i);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 27 Nov 2016 17:53:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-strings-using-macro/m-p/314626#M68559</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-11-27T17:53:02Z</dc:date>
    </item>
    <item>
      <title>Re: Generate strings using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-strings-using-macro/m-p/314630#M68563</link>
      <description>&lt;P&gt;Sorry, I was too buisy last days.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The rename you got:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; &amp;nbsp; var24 = v_10/13/2016&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;is the result of line&amp;nbsp;&lt;STRONG&gt;(in the macro)&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;datex &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;put&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;from_date&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;mmddyy10&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Just &lt;STRONG&gt;add &amp;nbsp;&lt;/STRONG&gt;next line after it, inside the macro:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;STRONG&gt;datex = translate(datex , '_' , '/');&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;to get the desired format:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;var24 = v_10_13_2016&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 27 Nov 2016 18:08:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-strings-using-macro/m-p/314630#M68563</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-11-27T18:08:45Z</dc:date>
    </item>
    <item>
      <title>Re: Generate strings using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-strings-using-macro/m-p/314632#M68565</link>
      <description>&lt;P&gt;Hey Tom,&lt;/P&gt;
&lt;P&gt;Here is my actual code it may help you to understand..&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/********* Importing Raw data ********************************************************/&lt;BR /&gt; proc import out = master&lt;BR /&gt; datafile = "c:\temp\file.txt"&lt;BR /&gt; dbms = dlm replace;&lt;BR /&gt; delimiter=';';&lt;BR /&gt; getnames = no;&lt;BR /&gt; run;&lt;/P&gt;
&lt;P&gt;Data want( &lt;BR /&gt; rename=&lt;BR /&gt; (Var1=Client_Number Var2=Report_Number Var3=PI Var4=SP Var5=Plan&amp;nbsp;&lt;BR /&gt; Var6=NP Var7=Sales Var8=RBS Var9=PG &amp;nbsp;Var10=Fe Var12=Prescriber Var13= First_Name Var14=Middle_Initial Var15=Address Var16=City Var17=ST Var18=Zip Var19=NP Var20=Pay Var21=DD Var22=Data_Date Var23=Maximum_Number_of_Buckets&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Var24=NRx_10_07_2016&lt;/P&gt;
&lt;P&gt;Var25=NRx_09_30_2016&lt;/P&gt;
&lt;P&gt;Var26=NRx_09_23_2016&lt;/P&gt;
&lt;P&gt;Var27=NRx_09_16_2016&lt;/P&gt;
&lt;P&gt;Var28=NRx_09_09_2016&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Var29=NRx_09_02_2016&lt;/P&gt;
&lt;P&gt;Var30=NRx_08_31_2016&lt;/P&gt;
&lt;P&gt;Var31=NRx_08_26_2016&lt;/P&gt;
&lt;P&gt;Var32=NRx_08_19_2016&lt;/P&gt;
&lt;P&gt;Var33=NRx_08_12_2016&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;..&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;.....&lt;/P&gt;
&lt;P&gt;..............&lt;/P&gt;
&lt;P&gt;Var150=NRx_10_03_2014&lt;/P&gt;
&lt;P&gt;Var151=NRx_09_30_2014&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/* same values for TRx now */&lt;/P&gt;
&lt;P&gt;Var152=TRx_10_07_2016&lt;/P&gt;
&lt;P&gt;Var153=TRx_09_30_2016 &lt;BR /&gt;Var154=TRx_09_23_2016&lt;/P&gt;
&lt;P&gt;Var155=TRx_09_16_2016&lt;/P&gt;
&lt;P&gt;........&lt;/P&gt;
&lt;P&gt;..........&lt;/P&gt;
&lt;P&gt;...........&lt;/P&gt;
&lt;P&gt;Var278=TRx_10_03_2014 &lt;BR /&gt;Var279=TRx_09_30_2014&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;/* same values for Nqty now */&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Var280=Nqty_10_07_2016 &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Var281=Nqty_09_30_2016&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;.......&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;..........&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;..........&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Var406=Nqty_10_03_2014 &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Var407=Nqty_09_30_2014&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;/* same values for Tqty&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;now */&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Var408=Tqty_10_07_2016&lt;BR /&gt;Var409=Tqty_09_30_2016&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Var410=Tqty_09_23_2016&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;..........................&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;...............&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;.............&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Var533=Tqty_10_10_2014 &lt;BR /&gt;Var534=Tqty_10_03_2014 &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Var535=Tqty_09_30_2014 ) );&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;set master;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;now I want to reduce my efforts becoze when I receive file the date of var22 will be diff now and according to that date&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I have maintain data for 24 months going backwards 7 days the same logic, that's why I need to rename my vars every time&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;when I get the file from client.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Please help me in here I hope I have made myself clear now.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 27 Nov 2016 18:16:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-strings-using-macro/m-p/314632#M68565</guid>
      <dc:creator>LittlesasMaster</dc:creator>
      <dc:date>2016-11-27T18:16:34Z</dc:date>
    </item>
    <item>
      <title>Re: Generate strings using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-strings-using-macro/m-p/314670#M68573</link>
      <description>&lt;P&gt;How are you dealing with these constantly changing variable names downstream? Doesn't that cause you&amp;nbsp;quite a bit of headache everywhere.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What about storing the data in a long format and then if you really need it in a wide format eg. for timeseries use Proc Transpose.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below a code sample storing the data in two tables. You can of course also create a single de-normalized table or further normalize your data. It's just an example to demonstrate the approach.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/** create sample data **/
%let source_file=c:\temp\test.csv;
data have; 
  array key_desc {21} $1 Client_Number Report_Number PI SP Plan NP1 Sales RBS PG Fe Var11 Prescriber First_Name Middle_Initial Address City ST Zip NP2 Pay DD (21*'C');
  length report_date Maximum_Number_of_Buckets 8;
  format report_date date9.;
  report_date='7oct2016'd;
  Maximum_Number_of_Buckets=3;
  array NRX {127}  $2 ('1' 126*'VA');
  array TRX {127}  $2 ('2' 126*'VB');
  array Nqty {127} $2 ('3' 126*'VC');
  array Tqty {127} $2 ('4' 126*'VE');
run;

proc export   
  data=have 
  outfile="&amp;amp;source_file"
  replace
  ;
  putnames=yes;
quit;


/** read sample data **/
data 
  cust_rep_dim (drop=bucket value date_point)
  cust_rep_fact(keep=cust_rep_key report_date bucket value date_point)
  ;
  length cust_rep_key $32;
  length report_date Maximum_Number_of_Buckets 8;
  format report_date date9.;
  array key_desc {21} $1 Client_Number Report_Number PI SP Plan NP1 Sales RBS PG Fe Var11 Prescriber First_Name Middle_Initial Address City ST Zip NP2 Pay DD;

  infile "&amp;amp;source_file" dlm=',' dsd truncover firstobs=2;
  input 
    (Client_Number Report_Number PI SP Plan NP1 Sales RBS PG Fe Var11 Prescriber First_Name Middle_Initial Address City ST Zip NP2 Pay DD) (:$1.) 
    report_date :date9. Maximum_Number_of_Buckets :best32.
    @;

  cust_rep_key=put(md5(catx('|',of key_desc[*])),hex32.);
  output cust_rep_dim;

  length bucket $4 value $2;
  format date_point date9.;
  do bucket='NRX','TRX','Nqty','Tqty';
    _cnt=0;
    do _i=0 to 126 while(_cnt&amp;lt;=126);
      _cnt+1;
      input value :$2. @;
      date_point=intnx('week',report_date,-_i,'s');
      if intck('month',date_point,intnx('week',report_date,-_i+1,'s')) ne 0 and intnx('month',date_point,0,'e') ne date_point then
        do;
          date_point=intnx('month',report_date,-1,'e');
          if not missing(value) then output cust_rep_fact;
          if _cnt&amp;lt;126 then 
            do;
              _cnt+1;
              input value :$2. @;
              date_point=intnx('week',report_date,-_i,'s');
              if not missing(value) then output cust_rep_fact;
            end;
        end;
      else
        if not missing(value) then output cust_rep_fact;
    end; /* end date loop */
  end; /* end bucket loop */
  drop _:;
run;
 
  &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 27 Nov 2016 22:46:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-strings-using-macro/m-p/314670#M68573</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2016-11-27T22:46:41Z</dc:date>
    </item>
    <item>
      <title>Re: Generate strings using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-strings-using-macro/m-p/322217#M71274</link>
      <description>&lt;P&gt;Hey Shmuel,&lt;/P&gt;
&lt;P&gt;I had created the macro and it's working fine but there is a slite change is output I require, I tried so many things but this is not working so I need ur help in here..&lt;/P&gt;
&lt;P&gt;I have written this code-&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/* is how I get date part, its okay I can deal with this*/&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;BR /&gt;date1="071016";&lt;BR /&gt;dd=substr(date1,1,2);&lt;BR /&gt;mm=substr(date1,3,2);&lt;BR /&gt;yy=substr(date1,5,2);&lt;BR /&gt;datex=mdy(mm,dd,yy);&lt;BR /&gt;call symputx("from_date",datex,'G');&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/* now I have got the date I will above date to start creating my values */&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro ren_vars;&lt;BR /&gt;data _null_;&lt;BR /&gt; length NRx $10000 renx $25 datex $10;&lt;BR /&gt; datex = compress("&amp;amp;from_date");&lt;BR /&gt; from_date = input(datex,10.); &lt;BR /&gt; format from_date mmddyy10.;&lt;BR /&gt; do vnum=24 to 151;&lt;BR /&gt; datex = put(from_date,mmddyy10.);&lt;BR /&gt; renx = cat("Var",vnum,' = ',"NRx_",datex); &lt;BR /&gt; renx=tranwrd(renx,"/","_");&lt;BR /&gt; NRx = trim(NRx) ||' '|| renx;&lt;BR /&gt; if day(from_date) &amp;gt; 7 then from_date = from_date - 7;&lt;BR /&gt; else from_date = intnx('month',from_date,-1,'e');&lt;BR /&gt; end;&lt;BR /&gt; call symputx('NRx',trim(NRx),'G');&lt;BR /&gt; run;&lt;BR /&gt;%put ------------------Nrx-------------------------------------;&lt;BR /&gt; %put &amp;amp;NRx;&lt;/P&gt;
&lt;P&gt;%mend ren_vars;&lt;/P&gt;
&lt;P&gt;%ren_vars;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;look at the output I am getting--- &amp;nbsp;few lines of output shown below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Var24 = NRx_10_07_20-16 Var25 = NRx_09_30_2016 Var26 = NRx_09_23_2016 Var27 = NRx_09_16_2016&lt;BR /&gt;Var28 = NRx_09_09_2016 Var29 = NRx_09_02_2016 Var30 = NRx_08_31_2016 Var31 = NRx_08_24_2016&lt;BR /&gt;Var32 = NRx_08_17_2016 Var33 = NRx_08_10_2016 Var34 = NRx_08_03_2016 Var35 = NRx_07_31_2016&lt;BR /&gt;Var36 = NRx_07_24_2016 Var37 = NRx_07_17_2016 Var38 = NRx_07_10_2016 Var39 = NRx_07_03_2016&lt;BR /&gt;Var40 = NRx_06_30_2016 Var41 = NRx_06_23_2016 Var42 = NRx_06_16_2016 Var43 = NRx_06_09_2016&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;what I want this is when it reaches to end of the month logic like we are checking if day&amp;gt;7 then keep substratcing 7 days from from_date but if day is &amp;lt;7 then that means it's going to next month so what we are asking system to go end of prev month and&lt;/P&gt;
&lt;P&gt;start over doing that -7 day logic but i want here that our code should split the 7 days logic if u look at the above code in line 2&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Var29 = NRx_09_02_2016 Var30 = NRx_08_31_2016 Var31 = NRx_08_24_2016&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;when our code came at 2nd day it found that ohh ok now this is less than 7 means go to end of pev month till this we are fine&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;Var30 = NRx_08_31_2016&lt;/STRONG&gt; but now&amp;nbsp;Var31 should only substract 5 days and should give result as&amp;nbsp;&lt;STRONG&gt;Var31=NRx_08_26_2016&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;so if you look colsely from 09-02 to 08-31 two days and then from 08-31 to 08-26 five days total comes 7 days&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;this is what I said split week, I am not able to find out logic , pls guide.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;below are the sample output to make u better understand the output which I am looking for---&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;----want----&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Var24=NRx_10_07_2016 Var25=NRx_09_30_2016 Var26=NRx_09_23_2016 Var27=NRx_09_16_2016 Var28=NRx_09_09_2016 &lt;BR /&gt;Var29=NRx_09_02_2016 Var30=NRx_08_31_2016 Var31=NRx_08_26_2016 Var32=NRx_08_19_2016 Var33=NRx_08_12_2016&lt;BR /&gt;Var34=NRx_08_05_2016 Var35=NRx_07_31_2016 Var36=NRx_07_29_2016 Var37=NRx_07_22_2016 Var38=NRx_07_15_2016 &lt;BR /&gt;Var39=NRx_07_08_2016 Var40=NRx_07_01_2016 Var41=NRx_06_30_2016 Var42=NRx_06_24_2016 Var43=NRx_06_17_2016 &lt;BR /&gt;Var44=NRx_06_10_2016 Var45=NRx_06_03_2016 Var46=NRx_05_31_2016 Var47=NRx_05_27_2016 Var48=NRx_05_20_2016 &lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Jan 2017 17:58:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-strings-using-macro/m-p/322217#M71274</guid>
      <dc:creator>LittlesasMaster</dc:creator>
      <dc:date>2017-01-03T17:58:28Z</dc:date>
    </item>
    <item>
      <title>Re: Generate strings using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-strings-using-macro/m-p/322259#M71288</link>
      <description>&lt;P&gt;1) Pay attention, &lt;STRONG&gt;MDY&lt;/STRONG&gt; function creates a numeric sas date variable containing&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; the number of days past since January 1st, 1960 up to given date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; You can shorten 1st step to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; data _null_;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;STRONG&gt;datex = input("07102016",ddmmyy10.) ;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;/* &amp;nbsp;or datex = '07OCT2016'd; */&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;call symputx("from_date",&lt;STRONG&gt;strip(&lt;/STRONG&gt;datex),'G');&lt;BR /&gt;&amp;nbsp; &amp;nbsp; run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) As &lt;STRONG&gt;from_date&lt;/STRONG&gt; is a number&amp;nbsp;you can make your &amp;nbsp;code more simple:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;instead:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro ren_vars;
data _null_;
length NRx $10000 renx $25 datex $10;
&lt;STRONG&gt;datex = compress("&amp;amp;from_date");
from_date = input(datex,10.);&lt;/STRONG&gt; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;you better use:&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;&amp;nbsp; &amp;nbsp; %macro ren_vars;
&amp;nbsp; &amp;nbsp; &amp;nbsp; data _null_;
&amp;nbsp; &amp;nbsp;  &amp;nbsp;length&amp;nbsp;NRx $10000 renx $25 datex $10;
&amp;nbsp; &amp;nbsp;   &lt;STRONG&gt;from_date = &amp;amp;from_date; &amp;nbsp; &amp;nbsp;&lt;/STRONG&gt;&amp;nbsp;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;3) As to splitting 7 days when changing month:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; instead&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do vnum=24 to 151;
     datex = put(from_date,mmddyy10.);
     renx = cat("Var",vnum,' = ',"NRx_",datex); 
     renx=tranwrd(renx,"/","_");
     NRx = trim(NRx) ||' '|| renx;
     if day(from_date) &amp;gt; 7 then from_date = from_date - 7;
     else from_date = intnx('month',from_date,-1,'e');
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; you need:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do vnum=24 to 151;
     datex = put(from_date,mmddyy10.);
     renx = cat("Var",vnum,' = ',"NRx_",datex); 
     renx=tranwrd(renx,"/","_");
     NRx = trim(NRx) ||' '|| renx;
     if day(from_date) &amp;gt; 7 then from_date = from_date - 7;
     else do;
             diff = day(from_date);
             from_date = intnx('month',from_date,-1,'e');
             datex = put(from_date,mmddyy10.);
             renx = cat("Var",vnum,' = ',"NRx_",datex); 
             renx=tranwrd(renx,"/","_");
             NRx = trim(NRx) ||' '|| renx;    

            if vnum = 151 then leave;
            vnum = vnum +1;
            from_date = from_date - 7 + diff;         
     end;
end;
DROP diff;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Jan 2017 21:56:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-strings-using-macro/m-p/322259#M71288</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-01-03T21:56:05Z</dc:date>
    </item>
  </channel>
</rss>

