<?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: Convert macro from requiring values to using variables to calculate a risk score in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Convert-macro-from-requiring-values-to-using-variables-to/m-p/914445#M360339</link>
    <description>&lt;P&gt;Thank you! I'm still very new to macros. This explanation is very appreciated.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 04 Feb 2024 20:16:30 GMT</pubDate>
    <dc:creator>sophiec</dc:creator>
    <dc:date>2024-02-04T20:16:30Z</dc:date>
    <item>
      <title>Convert macro from requiring values to using variables to calculate a risk score</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-macro-from-requiring-values-to-using-variables-to/m-p/914296#M360262</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am attempting to calculate participants' cardiovascular risk using a macro I found in a published paper. It requires common variables like blood pressure, age, sex, etc .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The macro works when I call it and reference specific values for each variable, as shown below. However, I would like to use it to calculate the risk score for thousands of participants (and not have to do each by hand) and eventually have it exported to a new dataset (still working on this also).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there any way to transform it from requiring values to referencing variables? I tried using %let and removing the = in the macro line, but neither were successful ("ERROR: Variable age is uninitialized")&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO PCE_RISK(AGE=, SEX=, TCHOL=, HDL=, SBP=, HTN=, SMK=, DIA=); 
DATA RISK;  
SCORE = (&amp;amp;SEX=0)*( -29.799*LOG(&amp;amp;AGE) +4.884*(LOG(&amp;amp;AGE)**2) 
			+13.540*LOG(&amp;amp;TCHOL) -3.114*LOG(&amp;amp;AGE)*LOG(&amp;amp;TCHOL) 
			-13.578*LOG(&amp;amp;HDL) +3.149*LOG(&amp;amp;AGE)*LOG(&amp;amp;HDL)  
			+(2.019*(&amp;amp;HTN=1)+1.957*(&amp;amp;HTN=0))*LOG(&amp;amp;SBP)
			+7.574*(&amp;amp;SMK=1)-1.665*LOG(&amp;amp;AGE)*(&amp;amp;SMK=1)
			+0.661*(&amp;amp;DIA=1))+    
		(&amp;amp;SEX=1)*(  +12.344*LOG(&amp;amp;AGE)+ 0*(LOG(&amp;amp;AGE)**2)  
			+11.853*LOG(&amp;amp;TCHOL)-2.664*LOG(&amp;amp;AGE)*LOG(&amp;amp;TCHOL) 
			-7.990*LOG(&amp;amp;HDL)+1.769*LOG(&amp;amp;AGE)*LOG(&amp;amp;HDL) 
			+(1.797*(&amp;amp;HTN=1)+1.764*(&amp;amp;HTN=0))*LOG(&amp;amp;SBP)
			+7.837*(&amp;amp;SMK=1)-1.795*LOG(&amp;amp;AGE)*(&amp;amp;SMK=1)
			+0.658*(&amp;amp;DIA=1));  
RISK = 100*(1 - (&amp;amp;SEX=0)*(0.96652**EXP(SCORE+29.1817)) - (&amp;amp;SEX=1)*(0.91436**EXP(SCORE-61.1816)) ); 
RUN;  
PROC PRINT DATA=RISKWHITE; RUN; %MEND; 

%PCE_RISK(AGE=55, SEX=0, TCHOL=200, HDL=60, SBP=130, HTN=1, SMK=0, DIA=1); run; 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Feb 2024 20:00:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-macro-from-requiring-values-to-using-variables-to/m-p/914296#M360262</guid>
      <dc:creator>sophiec</dc:creator>
      <dc:date>2024-02-02T20:00:37Z</dc:date>
    </item>
    <item>
      <title>Re: Convert macro from requiring values to using variables to calculate a risk score</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-macro-from-requiring-values-to-using-variables-to/m-p/914299#M360263</link>
      <description>&lt;P&gt;If you have all of these variables in a SAS data set, with the same names as the macro variables, just turn macro variables into data step variables in the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA RISK;  
    set your_data_set_name;
    SCORE = (SEX=0)*( -29.799*LOG(AGE) +4.884*(LOG(AGE)**2) 
	    +13.540*LOG(TCHOL) -3.114*LOG(AGE)*LOG(TCHOL) ...

        /* and so on, you do the rest */

    ; /* don't forget the semi-colon! */
    RISK = 100*(1 - (SEX=0)*(0.96652**EXP(SCORE+29.1817)) - (SEX=1)*(0.91436**EXP(SCORE-61.1816)) ); 
RUN;  &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 02 Feb 2024 20:22:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-macro-from-requiring-values-to-using-variables-to/m-p/914299#M360263</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-02-02T20:22:17Z</dc:date>
    </item>
    <item>
      <title>Re: Convert macro from requiring values to using variables to calculate a risk score</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-macro-from-requiring-values-to-using-variables-to/m-p/914300#M360264</link>
      <description>&lt;P&gt;If you have a data set with the variables holding the values to be used in that Score code then you could modify the code to something like the following code block.&lt;/P&gt;
&lt;P&gt;Where DSIN would be the name of your source data set. Then each observation would be scored.&lt;/P&gt;
&lt;P&gt;Personally I wouldn't automatically include proc print with a data set unless you really think you need to print that much stuff. Then place the names of your variables that hold the appropriate values instead of a litteral number. Those variables have to be in the correct units, values and numeric to be reliable with code like this.&lt;/P&gt;
&lt;PRE&gt;%MACRO PCE_RISK(DSIN= ,AGE=, SEX=, TCHOL=, HDL=, SBP=, HTN=, SMK=, DIA=); 
DATA RISK;  
   set &amp;amp;dsin. ;
   SCORE = (&amp;amp;SEX=0)*( -29.799*LOG(&amp;amp;AGE) +4.884*(LOG(&amp;amp;AGE)**2) 
			+13.540*LOG(&amp;amp;TCHOL) -3.114*LOG(&amp;amp;AGE)*LOG(&amp;amp;TCHOL) 
			-13.578*LOG(&amp;amp;HDL) +3.149*LOG(&amp;amp;AGE)*LOG(&amp;amp;HDL)  
			+(2.019*(&amp;amp;HTN=1)+1.957*(&amp;amp;HTN=0))*LOG(&amp;amp;SBP)
			+7.574*(&amp;amp;SMK=1)-1.665*LOG(&amp;amp;AGE)*(&amp;amp;SMK=1)
			+0.661*(&amp;amp;DIA=1))+    
		(&amp;amp;SEX=1)*(  +12.344*LOG(&amp;amp;AGE)+ 0*(LOG(&amp;amp;AGE)**2)  
			+11.853*LOG(&amp;amp;TCHOL)-2.664*LOG(&amp;amp;AGE)*LOG(&amp;amp;TCHOL) 
			-7.990*LOG(&amp;amp;HDL)+1.769*LOG(&amp;amp;AGE)*LOG(&amp;amp;HDL) 
			+(1.797*(&amp;amp;HTN=1)+1.764*(&amp;amp;HTN=0))*LOG(&amp;amp;SBP)
			+7.837*(&amp;amp;SMK=1)-1.795*LOG(&amp;amp;AGE)*(&amp;amp;SMK=1)
			+0.658*(&amp;amp;DIA=1));  
   RISK = 100*(1 - (&amp;amp;SEX=0)*(0.96652**EXP(SCORE+29.1817)) - (&amp;amp;SEX=1)*(0.91436**EXP(SCORE-61.1816)) ); 
RUN;  
PROC PRINT DATA=RISKWHITE; RUN;
%MEND; &lt;/PRE&gt;
&lt;P&gt;And the call would look like:&lt;/P&gt;
&lt;PRE&gt;%PCE_RISK(DSIN=mylib.somedataset, AGE=agevariablename, SEX=sexvar, TCHOL=tcholvar, HDL=hdlvar, SBP=sbpvar, HTN=htnvar, SMK=smkvar, DIA=diavar); run; &lt;/PRE&gt;
&lt;P&gt;I would be temped to make the output data set name optional as well.&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>Fri, 02 Feb 2024 20:22:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-macro-from-requiring-values-to-using-variables-to/m-p/914300#M360264</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-02-02T20:22:16Z</dc:date>
    </item>
    <item>
      <title>Re: Convert macro from requiring values to using variables to calculate a risk score</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-macro-from-requiring-values-to-using-variables-to/m-p/914308#M360267</link>
      <description>&lt;P&gt;Thank you so much! This worked perfectly!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Feb 2024 20:29:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-macro-from-requiring-values-to-using-variables-to/m-p/914308#M360267</guid>
      <dc:creator>sophiec</dc:creator>
      <dc:date>2024-02-02T20:29:16Z</dc:date>
    </item>
    <item>
      <title>Re: Convert macro from requiring values to using variables to calculate a risk score</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-macro-from-requiring-values-to-using-variables-to/m-p/914318#M360271</link>
      <description>&lt;P&gt;One of the advantages of Keword parameters to a macro, those defined like your Age=, is that you can provide a default value in the definition. So if you are likely to have a variable named Age in your data set you could define the macro with that default value for the parameter. Then if your data set has Age, or what ever you set as the default variable name, in the data set you don't need to pass it as a parameter.&lt;/P&gt;
&lt;P&gt;This can be handy if you know you are going to process multiple data sets with mostly the same variables.&lt;/P&gt;
&lt;P&gt;Then you only need to provide the variable name as a parameter when that particular data set uses a different name.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Feb 2024 20:45:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-macro-from-requiring-values-to-using-variables-to/m-p/914318#M360271</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-02-02T20:45:19Z</dc:date>
    </item>
    <item>
      <title>Re: Convert macro from requiring values to using variables to calculate a risk score</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-macro-from-requiring-values-to-using-variables-to/m-p/914445#M360339</link>
      <description>&lt;P&gt;Thank you! I'm still very new to macros. This explanation is very appreciated.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 04 Feb 2024 20:16:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-macro-from-requiring-values-to-using-variables-to/m-p/914445#M360339</guid>
      <dc:creator>sophiec</dc:creator>
      <dc:date>2024-02-04T20:16:30Z</dc:date>
    </item>
  </channel>
</rss>

