<?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: re-write code in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/re-write-code/m-p/808773#M318906</link>
    <description>thanks it works! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
    <pubDate>Wed, 20 Apr 2022 10:47:45 GMT</pubDate>
    <dc:creator>Toni2</dc:creator>
    <dc:date>2022-04-20T10:47:45Z</dc:date>
    <item>
      <title>re-write code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-write-code/m-p/808758#M318902</link>
      <description>&lt;P&gt;hi, i am quite new in SAS. I have found the below code in a SAS paper and try to apply it. My issue is i have problem with access to different libraries and therefore the "file" and "%inc" does not work for me.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to find a way to re-write the below code in one SAS program to avoid the "file" line and then the "%inc" or the file/%inc to be in my current process flow&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there any way to do it ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data _NULL_;
set PSI.endpoints end=last;
file "&amp;amp;PSILibrary\decileSample1.sas";
if _N_ = 1 then put " select;";
put " when (BinVar le " maxVar ") decile = " decile ";" ;
if last then do ;
put " otherwise decile = " decile ";" ;
put "end;";
call symput('maxbin',decile);
end;
run;

data PSI.PSISample2;
set PSI.PSISample2;
%inc "&amp;amp;PSILibrary\decileSample1.sas" / source;
If BinVar=. Then decile=&amp;amp;maxbin;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Apr 2022 09:29:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-write-code/m-p/808758#M318902</guid>
      <dc:creator>Toni2</dc:creator>
      <dc:date>2022-04-20T09:29:23Z</dc:date>
    </item>
    <item>
      <title>Re: re-write code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-write-code/m-p/808764#M318903</link>
      <description>&lt;P&gt;The first step in this code generates SAS code (text) that gets written to an external file as text. I've amended the syntax so this code gets written to a dynamically created file in SAS WORK (and only exists as long as your SAS session exists).&lt;/P&gt;
&lt;P&gt;The second data step then %includes this text file (that contains SAS syntax) and executes it.&lt;/P&gt;
&lt;P&gt;I've also changed option source to source&lt;STRONG&gt;2&lt;/STRONG&gt; in the %include statement. This will write to the SAS log the generated code that gets executed.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname psi &amp;lt;path to the folder where table endpoints exists&amp;gt;;
filename codegen temp;
data _null_;
  set psi.endpoints end=last;
  file codegen;
  if _n_ = 1 then put " select;";
  put " when (binvar le " maxvar ") decile = " decile ";";
  if last then
    do;
      put " otherwise decile = " decile ";";
      put "end;";
      call symput('maxbin',decile);
    end;
run;

data psi.psisample2;
  set psi.psisample2;
  %include codegen / source;
  if binvar=. then decile=&amp;amp;maxbin;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You will still need source table&amp;nbsp;&lt;CODE class=" language-sas"&gt;psi.endpoint&lt;/CODE&gt;&amp;nbsp;and you will need to define a &lt;EM&gt;libname &lt;STRONG&gt;psi&lt;/STRONG&gt; &amp;lt;path&amp;gt;;&lt;/EM&gt; that points to the directory where this table resides.&amp;nbsp;&amp;nbsp;&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>Wed, 20 Apr 2022 10:17:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-write-code/m-p/808764#M318903</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-04-20T10:17:28Z</dc:date>
    </item>
    <item>
      <title>Re: re-write code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/re-write-code/m-p/808773#M318906</link>
      <description>thanks it works! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Wed, 20 Apr 2022 10:47:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/re-write-code/m-p/808773#M318906</guid>
      <dc:creator>Toni2</dc:creator>
      <dc:date>2022-04-20T10:47:45Z</dc:date>
    </item>
  </channel>
</rss>

