<?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 How do i generalize a sphagetti sas code? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-generalize-a-sphagetti-sas-code/m-p/424186#M104433</link>
    <description>&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;I have a code that is very very long and extensive.&lt;/P&gt;
&lt;P&gt;How do i generalize/ normalize and make it reusable, that can be changed easily for a slightly different purpose?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Eg: i have something like&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) proc sql;&lt;BR /&gt;create table NEW as&lt;BR /&gt;(SELECT * FROM TBL A LEFT JOIN TBLB B&amp;nbsp;on A.COL1= B.COL2);&lt;BR /&gt;QUIT;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and a ...&lt;/P&gt;
&lt;P&gt;few more left join proc sql subqueries with casewhen statements,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) few retain and set stmts&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA new ;&lt;/P&gt;
&lt;P&gt;RETAIN&amp;nbsp;a b c ;&lt;BR /&gt;SET old;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3) Few infile stmts&lt;BR /&gt;data WORK.new;&lt;BR /&gt;%let _EFIERR_ = 0; /* set the ERROR detection macro variable */&lt;BR /&gt;infile 'C:\DESKTP.csv' delimiter = ',' MISSOVER DSD lrecl=32767&lt;BR /&gt;firstobs=2 ;&lt;BR /&gt;informat&amp;nbsp;a $3.&amp;nbsp;;&lt;BR /&gt;informat&amp;nbsp;b&amp;nbsp;$6. ;&lt;BR /&gt;format a $3. ;&lt;BR /&gt;input&lt;BR /&gt;a $&lt;BR /&gt;;&lt;BR /&gt;if _ERROR_ then call symputx('_EFIERR_',1); /* set ERROR detection macro variable */&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Few things that I&amp;nbsp;had already tried are&amp;nbsp;- using %let or macro passing parameters in several places.. but does not make sense to use %let for proc sql left join tables .. #1 above&amp;nbsp;&lt;/P&gt;
&lt;P&gt;for #3, I tried csv to import macros but couldnt apply informats and formats so had to stick to infile.. The goal here is to make it as reusable as it can be by changing a few things here and there.&lt;/P&gt;
&lt;P&gt;I also tried splitting up the code into parts for ease of understanding and then make my final code have only these statements below:-&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%include '..\part1.sas'&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;..&lt;/P&gt;
&lt;P&gt;%include '..\part7.sas'&lt;/P&gt;
&lt;P&gt;Any suggestions are welcome. Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 01 Jan 2018 00:02:36 GMT</pubDate>
    <dc:creator>swathi123</dc:creator>
    <dc:date>2018-01-01T00:02:36Z</dc:date>
    <item>
      <title>How do i generalize a sphagetti sas code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-generalize-a-sphagetti-sas-code/m-p/424186#M104433</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;I have a code that is very very long and extensive.&lt;/P&gt;
&lt;P&gt;How do i generalize/ normalize and make it reusable, that can be changed easily for a slightly different purpose?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Eg: i have something like&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) proc sql;&lt;BR /&gt;create table NEW as&lt;BR /&gt;(SELECT * FROM TBL A LEFT JOIN TBLB B&amp;nbsp;on A.COL1= B.COL2);&lt;BR /&gt;QUIT;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and a ...&lt;/P&gt;
&lt;P&gt;few more left join proc sql subqueries with casewhen statements,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) few retain and set stmts&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA new ;&lt;/P&gt;
&lt;P&gt;RETAIN&amp;nbsp;a b c ;&lt;BR /&gt;SET old;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3) Few infile stmts&lt;BR /&gt;data WORK.new;&lt;BR /&gt;%let _EFIERR_ = 0; /* set the ERROR detection macro variable */&lt;BR /&gt;infile 'C:\DESKTP.csv' delimiter = ',' MISSOVER DSD lrecl=32767&lt;BR /&gt;firstobs=2 ;&lt;BR /&gt;informat&amp;nbsp;a $3.&amp;nbsp;;&lt;BR /&gt;informat&amp;nbsp;b&amp;nbsp;$6. ;&lt;BR /&gt;format a $3. ;&lt;BR /&gt;input&lt;BR /&gt;a $&lt;BR /&gt;;&lt;BR /&gt;if _ERROR_ then call symputx('_EFIERR_',1); /* set ERROR detection macro variable */&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Few things that I&amp;nbsp;had already tried are&amp;nbsp;- using %let or macro passing parameters in several places.. but does not make sense to use %let for proc sql left join tables .. #1 above&amp;nbsp;&lt;/P&gt;
&lt;P&gt;for #3, I tried csv to import macros but couldnt apply informats and formats so had to stick to infile.. The goal here is to make it as reusable as it can be by changing a few things here and there.&lt;/P&gt;
&lt;P&gt;I also tried splitting up the code into parts for ease of understanding and then make my final code have only these statements below:-&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%include '..\part1.sas'&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;..&lt;/P&gt;
&lt;P&gt;%include '..\part7.sas'&lt;/P&gt;
&lt;P&gt;Any suggestions are welcome. Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jan 2018 00:02:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-generalize-a-sphagetti-sas-code/m-p/424186#M104433</guid>
      <dc:creator>swathi123</dc:creator>
      <dc:date>2018-01-01T00:02:36Z</dc:date>
    </item>
    <item>
      <title>Re: How do i generalize a sphagetti sas code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-generalize-a-sphagetti-sas-code/m-p/424190#M104437</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;The goal here is to make it as reusable as it can be by changing a few things here and there.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The key thing is to define the few things that might need changing and replace those with macro variables.&amp;nbsp; Then perhaps you can convert your long program into a macro.&amp;nbsp; That way you can just call it with the details of your current situation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Otherwise it looks like you just want to refactor&amp;nbsp;the code to make it more maintainable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Exactly how to refactor depends on what the code is doing.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example code with a log of CASE statements might easily be simplified by using a format or joining to a lookup table, but the exact details depend on the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You are right that you do NOT want to use PROC IMPORT if the goal is to run it on different input datasets.&amp;nbsp; PROC IMPORT must guess at what is in the file. It does that based on the specific data it is looking at. Give it a different set of data and it could make different guesses, even if the two files actually conform to the same file specifications.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jan 2018 01:40:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-generalize-a-sphagetti-sas-code/m-p/424190#M104437</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-01-01T01:40:18Z</dc:date>
    </item>
    <item>
      <title>Re: How do i generalize a sphagetti sas code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-generalize-a-sphagetti-sas-code/m-p/424198#M104443</link>
      <description>Build macros that make sense to be generalized, but for tasks that need things changed here and there make a reference program, copy and paste it and use the modified version. &lt;BR /&gt;&lt;BR /&gt;Once youve done that a few times you’ll have a handle on what can be generalized and what can’t be. &lt;BR /&gt;&lt;BR /&gt;Note that this is very generic advice for a very generic question. &lt;BR /&gt;</description>
      <pubDate>Mon, 01 Jan 2018 06:34:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-generalize-a-sphagetti-sas-code/m-p/424198#M104443</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-01-01T06:34:54Z</dc:date>
    </item>
    <item>
      <title>Re: How do i generalize a sphagetti sas code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-generalize-a-sphagetti-sas-code/m-p/424214#M104453</link>
      <description>&lt;P&gt;Thanks for your input. Here is my question. For proc sqls that may change for the code when used next time for a different purpose, there may be three left joins instead of one, and 2 proc sqls instead of 5. Would it make sense to generalize&amp;nbsp;the dataset&amp;nbsp;using a %let?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I feel like some of the code especially proc sql and infile example I had mentioned in my original question, cannot be reused.. ?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jan 2018 15:11:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-generalize-a-sphagetti-sas-code/m-p/424214#M104453</guid>
      <dc:creator>swathi123</dc:creator>
      <dc:date>2018-01-01T15:11:10Z</dc:date>
    </item>
    <item>
      <title>Re: How do i generalize a sphagetti sas code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-generalize-a-sphagetti-sas-code/m-p/424217#M104454</link>
      <description>&lt;P&gt;Hi Tom Thanks for your detailed reply. I am not trying to create a maintainable code, but my motto is to create a template for other types eg:: instead of running code tue, I may run it sunday for a different purpose. I can change macro var here to be reusable.. if i change %let it can run on diff day. I incorporated let statement here.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The tables I use may vary for my new goal, however it can leverage the same logic because it is doing slightly a different task but few portions of the code remains the same and can be reused..&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jan 2018 16:01:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-generalize-a-sphagetti-sas-code/m-p/424217#M104454</guid>
      <dc:creator>swathi123</dc:creator>
      <dc:date>2018-01-01T16:01:29Z</dc:date>
    </item>
    <item>
      <title>Re: How do i generalize a sphagetti sas code?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-i-generalize-a-sphagetti-sas-code/m-p/424219#M104455</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/46550"&gt;@swathi123&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for your input. Here is my question. For proc sqls that may change for the code when used next time for a different purpose, there may be three left joins instead of one, and 2 proc sqls instead of 5. Would it make sense to generalize&amp;nbsp;the dataset&amp;nbsp;using a %let?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I feel like some of the code especially proc sql and infile example I had mentioned in my original question, cannot be reused.. ?&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;In this case I don't think it does. The time to develop and make sure the macro logic is correct would be longer than the time it takes to copy the code and modify it manually. Also, SQL is harder to make into macro's especially controlling joins so IMO this doesn't make sense to generalize. I would have a template program that is well commented and can easily be modified&amp;nbsp;using %LET but that's about as far as I'd go when the process can vary from 2 to 5 PROC SQL.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jan 2018 17:43:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-i-generalize-a-sphagetti-sas-code/m-p/424219#M104455</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-01-01T17:43:37Z</dc:date>
    </item>
  </channel>
</rss>

