<?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: How to add enter when recursively creating a macro variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-enter-when-recursively-creating-a-macro-variable/m-p/443804#M111059</link>
    <description>&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;DO NOT HANDLE DATA IN MACRO LANGUAGE!&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;/U&gt;This is best solved by keeping a dataset with all pertinent information for the dates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See this example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data mydates;
input mydate date9.;
format mydate yymmddd10.;
cards;
13DEC2016
21DEC2016
20JAN2017
07FEB2017
22FEB2017
07MAR2017
21MAR2017
28MAR2017
04APR2017
07APR2017
10APR2017
11APR2017
12APR2017
13APR2017
14APR2017
17APR2017
18APR2017
19APR2017
21APR2017
24APR2017
26APR2017
27APR2017
02MAY2017
03MAY2017
04MAY2017
05MAY2017
08MAY2017
09MAY2017
;
/* lots of dates omitted, to keep code short */
run;

/* Find closest data to today's date 1 year ago */
data compare;
set mydates;
distance = abs(intck('days',intnx('year',today(),-1,'s'),mydate));
run;

proc sort data=compare;
by distance;
run;

data _null_;
set compare (obs=1);
call symputx('hist_date',put(mydate,best.));
put mydate date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 08 Mar 2018 15:44:11 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-03-08T15:44:11Z</dc:date>
    <item>
      <title>How to add enter when recursively creating a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-enter-when-recursively-creating-a-macro-variable/m-p/443791#M111054</link>
      <description>&lt;P&gt;I am trying to automate a program that compares today's data with data from last year's closest available date.&lt;/P&gt;&lt;P&gt;To do this I have a list of all the days we have data last year, and I have it loop through creating a list of distances from today's date.&amp;nbsp; I then calculate the minimum of these values.&amp;nbsp;&lt;/P&gt;&lt;P&gt;It works fine running it in SAS windows or EG, but when I try to run it in batch mode it crashes because the line of distances is too long.&lt;/P&gt;&lt;P&gt;I am trying to add a enter after every ten iterations, so the line is shorter.&amp;nbsp; However I can't figure out how to&amp;nbsp;concatenate using ENTER as a delimiter.&amp;nbsp; Here is my code, the part in bold is pseudo-code of what I want to happen:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;%let last_year=13DEC2016 21DEC2016 20JAN2017 07FEB2017&lt;BR /&gt;22FEB2017 07MAR2017 21MAR2017 28MAR2017 04APR2017 07APR2017 10APR2017 11APR2017&lt;BR /&gt;12APR2017 13APR2017 14APR2017 17APR2017 18APR2017 19APR2017 21APR2017 24APR2017&lt;BR /&gt;26APR2017 27APR2017 02MAY2017 03MAY2017 04MAY2017 05MAY2017 08MAY2017 09MAY2017&lt;BR /&gt;10MAY2017 11MAY2017 15MAY2017 16MAY2017 17MAY2017 18MAY2017 19MAY2017 22MAY2017&lt;BR /&gt;23MAY2017 24MAY2017 25MAY2017 26MAY2017 30MAY2017 31MAY2017 01JUN2017 06JUN2017&lt;BR /&gt;07JUN2017 14JUN2017 15JUN2017 16JUN2017 19JUN2017 20JUN2017 21JUN2017 22JUN2017&lt;BR /&gt;23JUN2017 26JUN2017 27JUN2017 28JUN2017 29JUN2017 30JUN2017 03JUL2017 05JUL2017&lt;BR /&gt;06JUL2017 10JUL2017 11JUL2017 12JUL2017 13JUL2017 14JUL2017 18JUL2017 19JUL2017&lt;BR /&gt;20JUL2017 25JUL2017 26JUL2017 27JUL2017 28JUL2017 31JUL2017 01AUG2017 02AUG2017&lt;BR /&gt;03AUG2017 04AUG2017 07AUG2017 08AUG2017 09AUG2017 10AUG2017 11AUG2017 15AUG2017&lt;BR /&gt;16AUG2017 17AUG2017;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let distlist0=;&lt;BR /&gt;%let total_days=%sysfunc(countw(&amp;amp;last_year.));&lt;BR /&gt;%let lastyrday=%sysevalf(%sysfunc(today())-365);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro histdate;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;%global distlist&amp;amp;total_days.;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;%do i=1 %to &amp;amp;total_days.;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%let j=%sysevalf(&amp;amp;i.-1);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%let date&amp;amp;i.=%sysevalf("%sysfunc(scan(&amp;amp;last_year.,&amp;amp;i.))"d);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%let dist&amp;amp;i.=%sysfunc(abs(&amp;amp;lastyrday.-&amp;amp;&amp;amp;date&amp;amp;i..));&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%let distlist&amp;amp;i.=%sysfunc(catx(%str(,),&amp;amp;&amp;amp;distlist&amp;amp;j..,&amp;amp;&amp;amp;dist&amp;amp;i..));&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%if %sysfunc(mod(&amp;amp;i.,10))=0 %then %let distlist&amp;amp;i.=&lt;EM&gt;&lt;STRONG&gt; &amp;amp;&amp;amp;distlist&amp;amp;i.. || ENTER&lt;/STRONG&gt;&lt;/EM&gt;;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;%end;&lt;BR /&gt;%mend;&lt;BR /&gt;%histdate;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let mindate=%sysfunc(min(&amp;amp;&amp;amp;distlist&amp;amp;total_days..));&lt;BR /&gt;%let minnum=%sysfunc(findw("&amp;amp;&amp;amp;distlist&amp;amp;total_days..",&amp;amp;mindate.,%str(,),%str(E)));&lt;BR /&gt;%let trimnum=%sysfunc(trim(&amp;amp;minnum.));&lt;BR /&gt;%let hist_date=%sysfunc(scan(%str(&amp;amp;last_year.),&amp;amp;trimnum.));&lt;/P&gt;&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Thu, 08 Mar 2018 15:33:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-enter-when-recursively-creating-a-macro-variable/m-p/443791#M111054</guid>
      <dc:creator>tyi7689okt</dc:creator>
      <dc:date>2018-03-08T15:33:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to add enter when recursively creating a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-enter-when-recursively-creating-a-macro-variable/m-p/443796#M111056</link>
      <description>&lt;P&gt;&lt;img id="smileyfrustrated" class="emoticon emoticon-smileyfrustrated" src="https://communities.sas.com/i/smilies/16x16_smiley-frustrated.png" alt="Smiley Frustrated" title="Smiley Frustrated" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Put your&amp;nbsp;&lt;U&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/U&gt; in a&amp;nbsp;&lt;U&gt;&lt;STRONG&gt;dataset&lt;/STRONG&gt;&lt;/U&gt; that is what they are used for.&amp;nbsp; If you can give some real example of test data in the form of a datastep and what you want out I will give you the code.&amp;nbsp; Macro is not there to do data processing, it is a find/replace system.&amp;nbsp; Base SAS is where you do processing as that as the data types, functions etc. and is the effectual compiled end product.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Mar 2018 15:39:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-enter-when-recursively-creating-a-macro-variable/m-p/443796#M111056</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-03-08T15:39:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to add enter when recursively creating a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-enter-when-recursively-creating-a-macro-variable/m-p/443804#M111059</link>
      <description>&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;DO NOT HANDLE DATA IN MACRO LANGUAGE!&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;/U&gt;This is best solved by keeping a dataset with all pertinent information for the dates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See this example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data mydates;
input mydate date9.;
format mydate yymmddd10.;
cards;
13DEC2016
21DEC2016
20JAN2017
07FEB2017
22FEB2017
07MAR2017
21MAR2017
28MAR2017
04APR2017
07APR2017
10APR2017
11APR2017
12APR2017
13APR2017
14APR2017
17APR2017
18APR2017
19APR2017
21APR2017
24APR2017
26APR2017
27APR2017
02MAY2017
03MAY2017
04MAY2017
05MAY2017
08MAY2017
09MAY2017
;
/* lots of dates omitted, to keep code short */
run;

/* Find closest data to today's date 1 year ago */
data compare;
set mydates;
distance = abs(intck('days',intnx('year',today(),-1,'s'),mydate));
run;

proc sort data=compare;
by distance;
run;

data _null_;
set compare (obs=1);
call symputx('hist_date',put(mydate,best.));
put mydate date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Mar 2018 15:44:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-enter-when-recursively-creating-a-macro-variable/m-p/443804#M111059</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-03-08T15:44:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to add enter when recursively creating a macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-enter-when-recursively-creating-a-macro-variable/m-p/443806#M111061</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
SELECT *, intnx("year",today(),-1,"s") AS oneYearAgo format=date9., abs(intck("day",dt,intnx("year",today(),-1,"s"))) AS distance
FROM HAVE
HAVING distance=min(distance)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Mar 2018 15:52:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-enter-when-recursively-creating-a-macro-variable/m-p/443806#M111061</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2018-03-08T15:52:20Z</dc:date>
    </item>
  </channel>
</rss>

