<?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 AND CONDITIONS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/MACRO-AND-CONDITIONS/m-p/808803#M318912</link>
    <description>&lt;P&gt;who authored this code? was it not you?&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 20 Apr 2022 12:48:09 GMT</pubDate>
    <dc:creator>tarheel13</dc:creator>
    <dc:date>2022-04-20T12:48:09Z</dc:date>
    <item>
      <title>MACRO AND CONDITIONS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-AND-CONDITIONS/m-p/808755#M318899</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro Generate_transformed_Scores
(variable=,
Has_Left=0,
Has_Right=0,
Left_value=0,
Right_Value=0,
Meaningful_Null=1,
condition1=LE-100000000,
condition2=LE-100000000,
condition3=LE-100000000,
condition4=LE-100000000,
condition5=LE-100000000,
condition6=LE-100000000,
condition7=LE-100000000,
condition8=LE-100000000,
condition9=LE-100000000);

&amp;amp;let variable1="&amp;amp;variable";
data transformation;
set &amp;amp;transform_para;
If var=&amp;amp;variable1;
format Null_score Slope Intercept b_score c_score d_score e_score f_Score g_score h_score i_score d19.14;
run;

Proc sql;
select Null_score into: Null_Score from transformation;
select Slope into: Slope from transformation;&lt;BR /&gt;Select Intercept into: Intercept from transformation;
select b_Score into: b_score from transformation;
select c_Score into: c_score from transformation;
select d_Score into: d_score from transformation;
select e_Score into: e_score from transformation;
select f_Score into: f_score from transformation;
select g_Score into: g_score from transformation;
select h_Score into: h_score from transformation;
select i_Score into: i_score from transformation;
quit;

data transformed_score_temp (keep=&amp;amp;variable score &amp;amp;matchby);
set &amp;amp;relevant_tab;
format Null_score Slope Intercept b_score c_score d_score e_score f_score g_Score h_Score i_Score d19.4;

score=&amp;amp;variable*&amp;amp;slope +&amp;amp;intercept;

if &amp;amp;Has_LEft=1 then do;
if &amp;amp;variable&amp;lt;&amp;amp;Left_Value then score=&amp;amp;Left_Value*&amp;amp;slope +&amp;amp;intercept;
end;

if &amp;amp;Has_Right=1 then do;
if &amp;amp;Variable &amp;gt; &amp;amp;Right_Value then score=&amp;amp;Right_Value*&amp;amp;slope+&amp;amp;intercept;
end;

if &amp;amp;variable &amp;amp;condition9. then score=&amp;amp;i_score;
if &amp;amp;variable &amp;amp;conditioon8. then score=&amp;amp;h_score;
if &amp;amp;variable &amp;amp;conditioon7. then score=&amp;amp;g_score;
if &amp;amp;variable &amp;amp;conditioon6. then score=&amp;amp;f_score;
if &amp;amp;variable &amp;amp;conditioon5. then score=&amp;amp;e_score;
if &amp;amp;variable &amp;amp;conditioon4. then score=&amp;amp;d_score;
if &amp;amp;variable &amp;amp;conditioon3. then score=&amp;amp;c_score;
if &amp;amp;variable &amp;amp;conditioon2. then score=&amp;amp;b_score;
if &amp;amp;variable &amp;amp;conditioon1. then score=&amp;amp;Null_score;
if &amp;amp;variable =. and &amp;amp;Meaningful_Null=1 then score=&amp;amp;Null_score;
if &amp;amp;variable =. and &amp;amp;Meaningful_Null=0 then score=.;
run;
&lt;BR /&gt;PROC SQL;&lt;BR /&gt;create table transformed_Score_temp as&lt;BR /&gt;select a.*, a.score as &amp;amp;variable._score&lt;BR /&gt;from transformed_Score_Temp as a, transformation as b;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table transformed_score_mast as&lt;BR /&gt;select a.*, b.&amp;amp;variable._score&lt;BR /&gt;from transformed_score_mast as a left join transformed_score_temp as b&lt;BR /&gt;on a.&amp;amp;IDField = b.&amp;amp;IDField and a.&amp;amp;IDField2=b.&amp;amp;IDField2;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table transformed_score as&lt;BR /&gt;select a.*, b.score as &amp;amp;variable., b.&amp;amp;variable. as &amp;amp;variable._O&lt;BR /&gt;from transformed_score_only as a left join transformed_Score_temp as b&lt;BR /&gt;on a.&amp;amp;IDField=b.&amp;amp;IDField and a.&amp;amp;IDField2=b.&amp;amp;IDField2;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;data transformed_score_only;&lt;BR /&gt;set transformed_Score;&lt;BR /&gt;run;&lt;BR /&gt;%mend;&lt;BR /&gt;
%Generate_transformed_scores (variables= (PctChangeBalance,&lt;BR /&gt;Has_Left=1,&lt;BR /&gt;HAs_Right=1,&lt;BR /&gt;Left_Value=0,&lt;BR /&gt;Right_Value=0.5,&lt;BR /&gt;condition=&amp;gt;0.5,&lt;BR /&gt;Meaningful_Null=0);&lt;BR /&gt;&lt;BR /&gt;%Generate_transformed_scores (variable=LongestOverdueMonth, &lt;BR /&gt;Has_Left=0,&lt;BR /&gt;Has_Right=0,&lt;BR /&gt;condition1=&amp;gt;3,&lt;BR /&gt;condition2=&amp;gt;=2,&lt;BR /&gt;condition3=&amp;gt;1,&lt;BR /&gt;condition4=&amp;lt;1,&lt;BR /&gt;Meaningful_Null=0);&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;
&lt;P&gt;Hi All, I am facing these macros where I am not sure how to interpret especially the part about the conditions like the below:&lt;/P&gt;
&lt;P&gt;if &amp;amp;variable &amp;amp;condition9. then score=&amp;amp;i_score;&lt;/P&gt;
&lt;P&gt;if &amp;amp;variable &amp;amp;conditioon8. then score=&amp;amp;h_score;&lt;/P&gt;
&lt;P&gt;if &amp;amp;variable &amp;amp;conditioon7. then score=&amp;amp;g_score;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What are we trying to achieve and what kind of return are we lightly to receive?&lt;/P&gt;</description>
      <pubDate>Wed, 20 Apr 2022 08:39:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-AND-CONDITIONS/m-p/808755#M318899</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2022-04-20T08:39:40Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO AND CONDITIONS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-AND-CONDITIONS/m-p/808757#M318901</link>
      <description>It is best to enable "options mprint symbolgen;" and submit macro program.&lt;BR /&gt;Then check the log.</description>
      <pubDate>Wed, 20 Apr 2022 08:59:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-AND-CONDITIONS/m-p/808757#M318901</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2022-04-20T08:59:00Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO AND CONDITIONS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-AND-CONDITIONS/m-p/808767#M318905</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/416388"&gt;@HeatherNewton&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;"What are we trying to achieve and what kind of return are we lightly to receive?"&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Is there no documentation? Kind-of scary if you're trying to re-engineer some developer's thinking just from code. Can you please provide a bit more information what you're dealing with here?&lt;/P&gt;</description>
      <pubDate>Wed, 20 Apr 2022 10:31:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-AND-CONDITIONS/m-p/808767#M318905</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-04-20T10:31:23Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO AND CONDITIONS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-AND-CONDITIONS/m-p/808803#M318912</link>
      <description>&lt;P&gt;who authored this code? was it not you?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Apr 2022 12:48:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-AND-CONDITIONS/m-p/808803#M318912</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2022-04-20T12:48:09Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO AND CONDITIONS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-AND-CONDITIONS/m-p/808804#M318913</link>
      <description>&lt;P&gt;&amp;nbsp;It is about credit card data, credit score card. unfortunately document does explain in much details of individual programs.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Apr 2022 12:48:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-AND-CONDITIONS/m-p/808804#M318913</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2022-04-20T12:48:41Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO AND CONDITIONS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-AND-CONDITIONS/m-p/808806#M318915</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Is there no documentation? Kind-of scary if you're trying to re-engineer some developer's thinking just from code.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Digression:&lt;/P&gt;
&lt;P&gt;I had this happen to me. A person who had my job before me wrote huge long extremely complicated SAS code, and never ever put any comments in the code ... except for one comment I remember ... it said "ARGGGGH This doesn't work!" ... very helpful. I remember one data step in the code was about 20 lines long and rather complicated, and when I finally figured out what was happening, this data step was just adding zeros and ones, which I replaced with PROC SUMMARY.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Apr 2022 13:06:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-AND-CONDITIONS/m-p/808806#M318915</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-04-20T13:06:57Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO AND CONDITIONS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-AND-CONDITIONS/m-p/808810#M318918</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/416388"&gt;@HeatherNewton&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;It is about credit card data, credit score card. unfortunately document does explain in much details of individual programs.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I don't think the question was about the subject matter (credit card data). The question was about: what does this program do? Can't you determine that from the output?&lt;/P&gt;</description>
      <pubDate>Wed, 20 Apr 2022 13:09:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-AND-CONDITIONS/m-p/808810#M318918</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-04-20T13:09:30Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO AND CONDITIONS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-AND-CONDITIONS/m-p/808811#M318919</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are a lot of problems with this macro.&amp;nbsp; But in terms of trying to understand it, remember that the macro language is all about text substitution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you call the macro like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%Generate_transformed_scores (variable=LongestOverdueMonth, 
Has_Left=0,
Has_Right=0,
condition1=&amp;gt;3,
condition2=&amp;gt;=2,
condition3=&amp;gt;1,
condition4=&amp;lt;1,
Meaningful_Null=0);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You are passing in values for macro variables, condition1-condition4.&amp;nbsp; Inside the macro, it creates the macro variables&amp;nbsp;b_score c_score d_score e_score f_Score g_score h_score i_score by reading values from an input dataset (We can't see the name of the input dataset, apparently the global macro variable Transform_para has the name.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let's pretend that the score macro have values:&amp;nbsp; d_score=100, c_score=10, b_score=1, Null_score=0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This line of code in the macro:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if &amp;amp;variable &amp;amp;conditioon4. then score=&amp;amp;d_score;
if &amp;amp;variable &amp;amp;conditioon3. then score=&amp;amp;c_score;
if &amp;amp;variable &amp;amp;conditioon2. then score=&amp;amp;b_score;
if &amp;amp;variable &amp;amp;conditioon1. then score=&amp;amp;Null_score;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Would resolve to:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if LongestOverdueMonth &amp;lt;1  then score=100;
if LongestOverdueMonth &amp;gt;1  then score=10;
if LongestOverdueMonth &amp;gt;=2 then score=1;
if LongestOverdueMonth &amp;gt;3  then score=0; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So it's a series of IF statements.&amp;nbsp; And it's a series of ugly, confusing IF statements that may overwrite the value of score several times because the conditions are not exclusive.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Both the macro, and the SAS code, are poorly designed.&amp;nbsp; I would suggest rewriting the macro.&amp;nbsp; Or, if you're not familiar with the macro language, I would suggest writing the program just SAS code, no macro language code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HTH,&lt;/P&gt;
&lt;P&gt;-Q.&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;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Apr 2022 13:08:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-AND-CONDITIONS/m-p/808811#M318919</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-04-20T13:08:06Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO AND CONDITIONS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-AND-CONDITIONS/m-p/808812#M318920</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Is there no documentation? Kind-of scary if you're trying to re-engineer some developer's thinking just from code.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Digression:&lt;/P&gt;
&lt;P&gt;I had this happen to me. A person who had my job before me wrote huge long extremely complicated SAS code, and never ever put any comments in the code ... except for one comment I remember ... it said "ARGGGGH This doesn't work!" ... very helpful. I remember one data step in the code was about 20 lines long and rather complicated, and when I finally figured out what was happening, this data step was just adding zeros and ones, which I replaced with PROC SUMMARY.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Another digression:&lt;/P&gt;
&lt;P&gt;My favorite comment in code I inherited along those lines was immediately after they had tried some sort of fuzzy merge.&amp;nbsp; And the comment said:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* Some of the records didn't match up correctly so I exported the data to Excel and fixed it then imported back into SAS. ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Oh, that's helpful.&lt;span class="lia-unicode-emoji" title=":face_with_tears_of_joy:"&gt;😂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Apr 2022 13:12:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-AND-CONDITIONS/m-p/808812#M318920</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-04-20T13:12:12Z</dc:date>
    </item>
  </channel>
</rss>

