<?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: Macro driven by sequential input file variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-driven-by-sequential-input-file-variable/m-p/38807#M7826</link>
    <description>Hi:&lt;BR /&gt;
  One trick that we used to use at a company that would not let SAS Macro programs in a production (scheduled job) was to do this:&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data _null_;&lt;BR /&gt;
  file 'yadayada.sas';&lt;BR /&gt;
  build statements in code and then PUT them to flat file;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
%include 'yadayada.sas';&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
  One advantage of this is that you can keep examining the "yadayada.sas" file to see that it's got the correct statements. We were allowed %include or SYSIN DD -- so it was a different approach but might work in this case.&lt;BR /&gt;
&lt;BR /&gt;
cynthia</description>
    <pubDate>Fri, 15 Aug 2008 16:11:56 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2008-08-15T16:11:56Z</dc:date>
    <item>
      <title>Macro driven by sequential input file variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-driven-by-sequential-input-file-variable/m-p/38803#M7822</link>
      <description>Hi Guys&lt;BR /&gt;
Am Rusty at this, so please excuse the dumb question - but its driving me mad!&lt;BR /&gt;
&lt;BR /&gt;
Start Point&lt;BR /&gt;
I have to read a large SAS file where each record contains (amongst other things) a char field NAM containing a variable name i.e 123abc99qz.&lt;BR /&gt;
&lt;BR /&gt;
This field is part of a full path id for a SAS Library i.e. /DIR1/DIR2/DIR3/123abc99qz/DIR4/.&lt;BR /&gt;
&lt;BR /&gt;
So, for each record on the input SAS file I need to:&lt;BR /&gt;
(1)Extract the NAM variable &amp;amp; Create the full path id . I do it thus : &lt;BR /&gt;
&lt;BR /&gt;
DATA FRED1;&lt;BR /&gt;
     Attrib FULL_PATH Length Length=$40;&lt;BR /&gt;
     Set INPUT_FILE(Keep=NAM);&lt;BR /&gt;
        FULL_PATH = '/PATH1/PATH2/' || NAM || '/PATH4/';&lt;BR /&gt;
        ARRAY FP_ARRAY (1) $ FULL_PATH;&lt;BR /&gt;
/* each FP_ARRAY variable now contains a valid SAS Library name */&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
(2) I now need to assign the value of each iteration of FULL_PATH to a variable that I can use to allocate a libname......&lt;BR /&gt;
DO I = 1 to DIM(FP_ARRAY)&lt;BR /&gt;
     CALL SYMPUT ('LIB_ID',FP_ARRAY(i));&lt;BR /&gt;
     LIBNAME LIBLIB "&amp;amp;LIB_ID".&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
END;   &lt;BR /&gt;
&lt;BR /&gt;
(2)Run Proc sort on a filename in this Library with "out=" &amp;amp; "where" parameters.&lt;BR /&gt;
    Easy - once the Library can be assigned&lt;BR /&gt;
PROC SORT DATA=LIBLIB.filename;&lt;BR /&gt;
                    OUT=CUT1;&lt;BR /&gt;
                    WHERE();&lt;BR /&gt;
(3)Run Proc Append to add the out= file specified previously to a permanent D/Set &lt;BR /&gt;
    (Again - Easy once the Library is assigned)&lt;BR /&gt;
&lt;BR /&gt;
(4) Read the next record on the File untill all are processed.&lt;BR /&gt;
&lt;BR /&gt;
I know that all processing must be done within FRED1 else the array will disappear...but it has me tearing my hair out.&lt;BR /&gt;
&lt;BR /&gt;
Any advice on how to proceed (or indeed, an alternate processing suggestion) would be most appreciated.</description>
      <pubDate>Wed, 13 Aug 2008 14:42:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-driven-by-sequential-input-file-variable/m-p/38803#M7822</guid>
      <dc:creator>Trog</dc:creator>
      <dc:date>2008-08-13T14:42:50Z</dc:date>
    </item>
    <item>
      <title>Re: Macro driven by sequential input file variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-driven-by-sequential-input-file-variable/m-p/38804#M7823</link>
      <description>If not interested in using MACRO language, consider using CALL EXECUTE to assign a SAS variable that contains each of your well-defined PROC steps.  No array needed - just generate the SAS code and the steps will be executed serially after your main DATA step completes.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Wed, 13 Aug 2008 15:56:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-driven-by-sequential-input-file-variable/m-p/38804#M7823</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2008-08-13T15:56:44Z</dc:date>
    </item>
    <item>
      <title>Re: Macro driven by sequential input file variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-driven-by-sequential-input-file-variable/m-p/38805#M7824</link>
      <description>Hi Scott&lt;BR /&gt;
Its not that i'm not interested in using the Macro language - I'm happy to use anything that works!.&lt;BR /&gt;
Thanks for your advice &lt;BR /&gt;
&lt;BR /&gt;
Best regards,&lt;BR /&gt;
&lt;BR /&gt;
Trog</description>
      <pubDate>Fri, 15 Aug 2008 07:38:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-driven-by-sequential-input-file-variable/m-p/38805#M7824</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-08-15T07:38:13Z</dc:date>
    </item>
    <item>
      <title>Re: Macro driven by sequential input file variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-driven-by-sequential-input-file-variable/m-p/38806#M7825</link>
      <description>It's only that using MACRO language increased the PITA effect for debugging, because....let's see, where should I start...NO LINE NUMBERS REVEALED!!  Sorry, increased cuban coffee consumption this Friday.  Understandably, some have an aversion to embracing the SAS macro language unless absolutely required.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Fri, 15 Aug 2008 12:14:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-driven-by-sequential-input-file-variable/m-p/38806#M7825</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2008-08-15T12:14:58Z</dc:date>
    </item>
    <item>
      <title>Re: Macro driven by sequential input file variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-driven-by-sequential-input-file-variable/m-p/38807#M7826</link>
      <description>Hi:&lt;BR /&gt;
  One trick that we used to use at a company that would not let SAS Macro programs in a production (scheduled job) was to do this:&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data _null_;&lt;BR /&gt;
  file 'yadayada.sas';&lt;BR /&gt;
  build statements in code and then PUT them to flat file;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
%include 'yadayada.sas';&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
  One advantage of this is that you can keep examining the "yadayada.sas" file to see that it's got the correct statements. We were allowed %include or SYSIN DD -- so it was a different approach but might work in this case.&lt;BR /&gt;
&lt;BR /&gt;
cynthia</description>
      <pubDate>Fri, 15 Aug 2008 16:11:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-driven-by-sequential-input-file-variable/m-p/38807#M7826</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2008-08-15T16:11:56Z</dc:date>
    </item>
    <item>
      <title>Re: Macro driven by sequential input file variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-driven-by-sequential-input-file-variable/m-p/38808#M7827</link>
      <description>Hi Trog&lt;BR /&gt;
Here a code example for what others already described:&lt;BR /&gt;
&lt;BR /&gt;
data have;&lt;BR /&gt;
  var1='c:\';&lt;BR /&gt;
  NAM='tests';&lt;BR /&gt;
  output;&lt;BR /&gt;
  var1='c:\';&lt;BR /&gt;
  NAM='tests2';&lt;BR /&gt;
  output;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
%macro DoSomething(PathPart=,NamVal=,ds=hugo);&lt;BR /&gt;
  %let path=&amp;amp;PathPart.&amp;amp;NamVal;&lt;BR /&gt;
  libname xx "&amp;amp;path" access=readonly;&lt;BR /&gt;
  proc sort data=xx.&amp;amp;ds out=work.&amp;amp;ds;&lt;BR /&gt;
    by country;&lt;BR /&gt;
  run;&lt;BR /&gt;
  libname xx clear;&lt;BR /&gt;
  libname yy 'c:\tests3';&lt;BR /&gt;
  proc append base=yy.AllTogether data=work.&amp;amp;ds force;&lt;BR /&gt;
  run;&lt;BR /&gt;
  libname yy clear;&lt;BR /&gt;
%mend;&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
  set have;&lt;BR /&gt;
  call execute ('%DoSomething(PathPart='||var1||',NamVal='||Nam||')');&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick</description>
      <pubDate>Fri, 15 Aug 2008 20:30:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-driven-by-sequential-input-file-variable/m-p/38808#M7827</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2008-08-15T20:30:49Z</dc:date>
    </item>
  </channel>
</rss>

