<?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: Don't know what's wrong with my (simple) macro function in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Don-t-know-what-s-wrong-with-my-simple-macro-function/m-p/429011#M105948</link>
    <description>&lt;P&gt;&lt;STRONG&gt;You wrote&lt;/STRONG&gt;-&lt;EM&gt;"My dataset looks like this. I want to make a macro function that would take in a name of an&amp;nbsp;analyte and print out all the observations with "Low" or "High" for that&amp;nbsp;analyte."&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;Ok, Thank you. So it looks like your dataset has variables SODCAT--LDLCAT that are already formatted using the formats defined in your list of proc format statements. If this is really the case, I see no big deal:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro analyte(analyte=sodcat);

data want;

set have;

where upcase(&amp;amp;analyte)='LOW' or upcase(&amp;amp;analyte)='HIGH';

run;

proc print data =want;

run;

%mend analyte;

%analyte

/*macro var analyte takes the value as user assigned for each analyte such as sodcat, calcat, procat etc*/

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 19 Jan 2018 05:20:55 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-01-19T05:20:55Z</dc:date>
    <item>
      <title>Don't know what's wrong with my (simple) macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Don-t-know-what-s-wrong-with-my-simple-macro-function/m-p/428998#M105940</link>
      <description>&lt;P&gt;&lt;STRONG&gt;First, I'm creating a new dataset with new names for some variables.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Dropping unwanted variables&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data q2;&lt;BR /&gt;set METSdata.LABA_669;&lt;BR /&gt;rename LABA11 =&amp;nbsp;SODIUM&amp;nbsp;&lt;BR /&gt;LABA15 =&amp;nbsp;CALCIUM&amp;nbsp;&lt;BR /&gt;LABA16 =&amp;nbsp;PROTEIN&amp;nbsp;&lt;BR /&gt;LABA5 = HDL&lt;BR /&gt;LABA6 = LDL;&lt;BR /&gt;keep BID VISIT LABA11 LABA15 LABA16 LABA5 LABA6;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc print data=q2 (obs=20); run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;The dataset contains a lot &lt;/STRONG&gt;of .&lt;STRONG&gt; values. I want to categorize numeric&amp;amp;. values into within a range and outside of the range, by labeling them Missing, Low, Normal (within range), and High. I'm using different categories for&amp;nbsp;different variables (such as sodium (SOD), calcium(CAL), etc)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc format;&lt;BR /&gt;value SOD&lt;BR /&gt;. = 'Missing'&lt;BR /&gt;Low-129 = 'Low'&lt;BR /&gt;130&amp;lt;-&amp;lt;150 = 'Normal'&lt;BR /&gt;151-High = 'High';&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc format;&lt;BR /&gt;value CAL&lt;BR /&gt;. = 'Missing'&lt;BR /&gt;Low-7= 'Low'&lt;BR /&gt;8&amp;lt;-&amp;lt;10.5 = 'Normal'&lt;BR /&gt;11-High = 'High';&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc format;&lt;BR /&gt;value PRO&lt;BR /&gt;. = 'Missing'&lt;BR /&gt;Low-5 = 'Low'&lt;BR /&gt;6&amp;lt;-&amp;lt;9 = 'Normal'&lt;BR /&gt;10-High = 'High';&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc format;&lt;BR /&gt;value HDL&lt;BR /&gt;. = 'Missing'&lt;BR /&gt;Low-24 = 'Low'&lt;BR /&gt;25-High = 'Normal';&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc format;&lt;BR /&gt;value LDL&lt;BR /&gt;. = 'Missing'&lt;BR /&gt;Low-200 = 'Normal'&lt;BR /&gt;201-High = 'High';&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Then onto macro function - I'm creating a function such that if I type Sodium, Calcium, etc, the function will create a categorical variable, which is a categorized version of the numeric&amp;amp;. values accordingly to the input name, then print&amp;nbsp;BID VISIT &amp;amp;name. and valcat&amp;nbsp;variables of that input name.&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%macro analyte(name=);&lt;BR /&gt;data &amp;amp;name.;&lt;BR /&gt;set q2;&lt;BR /&gt;valcat = &amp;amp;name.;&lt;BR /&gt;&lt;BR /&gt;%if upcase(&amp;amp;name.) = SODIUM %then&lt;BR /&gt;%put %sysfunc(putn(&amp;amp;valcat, SOD.));&lt;BR /&gt;&lt;BR /&gt;%if upcase(&amp;amp;name.) = CALCIUM %then&lt;BR /&gt;%put %sysfunc(putn(&amp;amp;valcat, CAL.));&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%if upcase(&amp;amp;name.) = PROTEIN %then&lt;BR /&gt;%put %sysfunc(putn(&amp;amp;valcat, PRO.));&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%if upcase(&amp;amp;name.) = HDL %then&lt;BR /&gt;%put %sysfunc(putn(&amp;amp;valcat, HDL.));&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%else upcase(&amp;amp;name.) = LDL&lt;BR /&gt;%put %sysfunc(putn(&amp;amp;valcat, LDL.));&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;keep BID VISIT &amp;amp;name. valcat;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc print data = &amp;amp;name.; run;&lt;BR /&gt;%macro analyte;&lt;/P&gt;&lt;P&gt;%analyte(sodium);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't get any output from this macro function though.&amp;nbsp;Any help please?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jan 2018 03:50:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Don-t-know-what-s-wrong-with-my-simple-macro-function/m-p/428998#M105940</guid>
      <dc:creator>gsk</dc:creator>
      <dc:date>2018-01-19T03:50:12Z</dc:date>
    </item>
    <item>
      <title>Re: Don't know what's wrong with my (simple) macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Don-t-know-what-s-wrong-with-my-simple-macro-function/m-p/429000#M105941</link>
      <description>&lt;P&gt;I'm afraid you have got the entire concept of &lt;STRONG&gt;macro timing vs datastep timing&lt;/STRONG&gt; completely mixed up besides syntax issues such as missing double quotes in macro reference in a datastep. Simple or complex doesn't matter if it's timing issue.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jan 2018 04:13:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Don-t-know-what-s-wrong-with-my-simple-macro-function/m-p/429000#M105941</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-01-19T04:13:04Z</dc:date>
    </item>
    <item>
      <title>Re: Don't know what's wrong with my (simple) macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Don-t-know-what-s-wrong-with-my-simple-macro-function/m-p/429001#M105942</link>
      <description>Could you help identify where to start/fix?</description>
      <pubDate>Fri, 19 Jan 2018 04:16:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Don-t-know-what-s-wrong-with-my-simple-macro-function/m-p/429001#M105942</guid>
      <dc:creator>gsk</dc:creator>
      <dc:date>2018-01-19T04:16:45Z</dc:date>
    </item>
    <item>
      <title>Re: Don't know what's wrong with my (simple) macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Don-t-know-what-s-wrong-with-my-simple-macro-function/m-p/429004#M105945</link>
      <description>&lt;P&gt;First off, You can get a super efficient code from experts here than to fix a code that may deemed not good. So, If you let the community know your needs with samples of your datasets, it's easy for them to give you the best possible solutions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyway, since the question relates to your code, I have commented a bit to give you a heads up&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro analyte(name=);
data &amp;amp;name.;
set q2;
valcat = "&amp;amp;name.";/* this should be in double quotes*/
/*%if is macro language statement and not a sas datastep execution statement*/
%if upcase(&amp;amp;name.) = SODIUM %then
%put %sysfunc(putn(&amp;amp;valcat, SOD.));	/*valcat is a datastep variable and not a macro variable and the same goes for all statements*/

%if upcase(&amp;amp;name.) = CALCIUM %then
%put %sysfunc(putn(&amp;amp;valcat, CAL.));


%if upcase(&amp;amp;name.) = PROTEIN %then
%put %sysfunc(putn(&amp;amp;valcat, PRO.));


%if upcase(&amp;amp;name.) = HDL %then
%put %sysfunc(putn(&amp;amp;valcat, HDL.));


%else upcase(&amp;amp;name.) = LDL
%put %sysfunc(putn(&amp;amp;valcat, LDL.));


keep BID VISIT &amp;amp;name. valcat;
run;

proc print data = &amp;amp;name.; run;
%macro analyte;

%analyte(sodium);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Jan 2018 04:28:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Don-t-know-what-s-wrong-with-my-simple-macro-function/m-p/429004#M105945</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-01-19T04:28:55Z</dc:date>
    </item>
    <item>
      <title>Re: Don't know what's wrong with my (simple) macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Don-t-know-what-s-wrong-with-my-simple-macro-function/m-p/429007#M105946</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="capture.JPG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/17966iE18C988580C4F937/image-size/large?v=v2&amp;amp;px=999" role="button" title="capture.JPG" alt="capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;My dataset looks like this. I want to make a macro function that would take in a name of an&amp;nbsp;analyte and print out all the observations with "Low" or "High" for that&amp;nbsp;&lt;SPAN&gt;analyte.&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jan 2018 04:54:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Don-t-know-what-s-wrong-with-my-simple-macro-function/m-p/429007#M105946</guid>
      <dc:creator>gsk</dc:creator>
      <dc:date>2018-01-19T04:54:09Z</dc:date>
    </item>
    <item>
      <title>Re: Don't know what's wrong with my (simple) macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Don-t-know-what-s-wrong-with-my-simple-macro-function/m-p/429011#M105948</link>
      <description>&lt;P&gt;&lt;STRONG&gt;You wrote&lt;/STRONG&gt;-&lt;EM&gt;"My dataset looks like this. I want to make a macro function that would take in a name of an&amp;nbsp;analyte and print out all the observations with "Low" or "High" for that&amp;nbsp;analyte."&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;Ok, Thank you. So it looks like your dataset has variables SODCAT--LDLCAT that are already formatted using the formats defined in your list of proc format statements. If this is really the case, I see no big deal:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro analyte(analyte=sodcat);

data want;

set have;

where upcase(&amp;amp;analyte)='LOW' or upcase(&amp;amp;analyte)='HIGH';

run;

proc print data =want;

run;

%mend analyte;

%analyte

/*macro var analyte takes the value as user assigned for each analyte such as sodcat, calcat, procat etc*/

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jan 2018 05:20:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Don-t-know-what-s-wrong-with-my-simple-macro-function/m-p/429011#M105948</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-01-19T05:20:55Z</dc:date>
    </item>
    <item>
      <title>Re: Don't know what's wrong with my (simple) macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Don-t-know-what-s-wrong-with-my-simple-macro-function/m-p/429013#M105950</link>
      <description>&lt;P&gt;Thanks a lot, that's neat!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I've been trying to keep variables including the original values and categorical variable of the analyte by doing below;&amp;nbsp; I just added the italicized&amp;nbsp;part and it doesn't work. I get errors saying that the s&lt;SPAN&gt;tatements are not valid or used out of proper order. Why am I getting these errors?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%macro analyte(analyte=sodcat);&lt;BR /&gt;data want;&lt;BR /&gt;set q2;&lt;BR /&gt;where upcase(&amp;amp;analyte) in ('LOW','HIGH');&lt;BR /&gt;&lt;BR /&gt;&lt;EM&gt;if &amp;amp;analyte eq sodcat then&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;keep BID VISIT Sodium &amp;amp;analyte;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;else if &amp;amp;analyte eq calcat then&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;keep BID VISIT Calcium &amp;amp;analyte;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;else if &amp;amp;analyte eq procat then &lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;keep BID VISIT Protein &amp;amp;analyte;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;else if &amp;amp;analyte eq hdlcat then &lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;keep BID VISIT hdl &amp;amp;analyte;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;else&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;keep BID VISIT ldl &amp;amp;analyte;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;run;&lt;/EM&gt;&lt;BR /&gt;&lt;BR /&gt;proc print data =want;&lt;BR /&gt;run;&lt;BR /&gt;%mend analyte;&lt;/P&gt;&lt;P&gt;%analyte&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jan 2018 06:17:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Don-t-know-what-s-wrong-with-my-simple-macro-function/m-p/429013#M105950</guid>
      <dc:creator>gsk</dc:creator>
      <dc:date>2018-01-19T06:17:30Z</dc:date>
    </item>
    <item>
      <title>Re: Don't know what's wrong with my (simple) macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Don-t-know-what-s-wrong-with-my-simple-macro-function/m-p/429014#M105951</link>
      <description>&lt;P&gt;Ok good. This is where you need a macro %if %then %else&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro analyte(analyte=sodcat);
data want;
set q2;
where upcase(&amp;amp;analyte) in ('LOW','HIGH');

%if &amp;amp;analyte eq sodcat %then
%str(keep BID VISIT Sodium &amp;amp;analyte;);
%else %if &amp;amp;analyte eq calcat %then
%str(keep BID VISIT Calcium &amp;amp;analyte;);
%else %if &amp;amp;analyte eq procat %then 
%str(keep BID VISIT Protein &amp;amp;analyte;);
%else %if &amp;amp;analyte eq hdlcat %then 
%str(keep BID VISIT hdl &amp;amp;analyte;);
%else
%str(keep BID VISIT ldl &amp;amp;analyte;);
run;

proc print data =want;
run;
%mend analyte;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;watch out for my typo based syntax errors just in case&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jan 2018 06:34:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Don-t-know-what-s-wrong-with-my-simple-macro-function/m-p/429014#M105951</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-01-19T06:34:03Z</dc:date>
    </item>
    <item>
      <title>Re: Don't know what's wrong with my (simple) macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Don-t-know-what-s-wrong-with-my-simple-macro-function/m-p/429017#M105953</link>
      <description>Thank you so much!! I hope I can get better..</description>
      <pubDate>Fri, 19 Jan 2018 06:51:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Don-t-know-what-s-wrong-with-my-simple-macro-function/m-p/429017#M105953</guid>
      <dc:creator>gsk</dc:creator>
      <dc:date>2018-01-19T06:51:20Z</dc:date>
    </item>
    <item>
      <title>Re: Don't know what's wrong with my (simple) macro function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Don-t-know-what-s-wrong-with-my-simple-macro-function/m-p/429052#M105963</link>
      <description>&lt;P&gt;Why not use CDISC standards on your data?&amp;nbsp; These have been carefully thought out over years to provide a simple functional model for your data.&amp;nbsp; In this instance, each of you lab parameters would become rows with result, unit etc. information on it.&amp;nbsp; Then you only need simple datasteps to process lots of observations.&amp;nbsp; Working with transposed data is always going to make your code far more complicated, harder to maintain.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jan 2018 09:04:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Don-t-know-what-s-wrong-with-my-simple-macro-function/m-p/429052#M105963</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-01-19T09:04:38Z</dc:date>
    </item>
  </channel>
</rss>

