<?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: Problem with Macro Variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-Macro-Variable/m-p/499423#M132901</link>
    <description>&lt;P&gt;And work on consistent visual formatting and a consistent coding style.&lt;/P&gt;
&lt;P&gt;Compare this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let variable=Glucose;

data alle.&amp;amp;variable._t0 (keep=
  studie bmid bmdt_int bmankli_d bmankli_u abndat parameter wert
  uhrzeit zeit minuten &amp;amp;variable._ank_dat &amp;amp;variable._ank_wert
  &amp;amp;variable._tag1_wert &amp;amp;variable._ank_comment &amp;amp;variable._tag1_comment
);
format
  &amp;amp;variable._ank_dat ddmmyy10.
  &amp;amp;variable._ank_wert
  &amp;amp;variable._tag1_wert
  &amp;amp;variable._ank_comment
  &amp;amp;variable._tag1_comment
    $50.
  uhrzeit hhmm5.
  minuten 4.
;
set alle.merge_ank_lab_1;
uhrzeit = timepart(zeit);
minuten = intck('minute',bmankli_u,uhrzeit);
if bmankli_d = abndat;
if wert not in('.','n.nwb.','neg','neg.');
if
  0 &amp;lt;= minuten &amp;lt;= 70 and not missing(bmankli_d)
  and not missing(bmankli_u) and parameter = "&amp;amp;variable."
then do; 
  &amp;amp;variable._ank_dat = abndat;
  &amp;amp;variable._ank_wert = wert;
  &amp;amp;variable._ank_comment = 'Abnahme 0 bis 70 min nach Aufnahme';
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;with your original code.&lt;/P&gt;</description>
    <pubDate>Thu, 27 Sep 2018 10:16:06 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-09-27T10:16:06Z</dc:date>
    <item>
      <title>Problem with Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-Macro-Variable/m-p/499412#M132893</link>
      <description>&lt;P&gt;Dear users,&lt;/P&gt;&lt;P&gt;i wrote a Macro to select some of&amp;nbsp; a long list of blood levels (over 100.000).&lt;/P&gt;&lt;P&gt;especially here glucosis.&lt;/P&gt;&lt;P&gt;The Problem is how to insert correctly the macro variable ... this part does not work &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt; to select only the glucosis&lt;/P&gt;&lt;PRE&gt;parameter in ('&amp;amp;variable')&lt;/PRE&gt;&lt;P&gt;here the complete code&lt;/P&gt;&lt;PRE&gt;options mcompilenote=all;

%macro sort_macr (variable);

DATA alle.&amp;amp;variable._T0 (keep =studie bmid bmdt_int bmankli_d bmankli_u abndat parameter wert Uhrzeit zeit minuten	&amp;amp;variable._ank_dat &amp;amp;variable._ank_wert &amp;amp;variable._Tag1_wert &amp;amp;variable._ank_comment &amp;amp;variable._Tag1_comment);

FORMAT 	&amp;amp;variable._ank_dat DDMMYY10.

	   	&amp;amp;variable._ank_wert &amp;amp;variable._Tag1_wert  $50.
	
	   	&amp;amp;variable._ank_comment &amp;amp;variable._Tag1_comment  $50.

		Uhrzeit HHMM5.
		minuten 4.;

SET alle.merge_ank_lab_1;

Uhrzeit=timepart(zeit);
minuten=INTCK('minute',bmankli_u,Uhrzeit);


if bmankli_d = abndat;

if wert not in('.','n.nwb.','neg','neg.');


if 0 &amp;lt;= minuten&amp;lt;=70 and not missing (bmankli_d) and not missing (bmankli_u) and parameter in ('&amp;amp;variable')  then do; 
&amp;amp;variable._ank_dat=abndat;
&amp;amp;variable._ank_wert=wert;
&amp;amp;variable._ank_comment = 'Abnahme 0 bis 70 min nach Aufnahme';
end;

RUN;

%mend;

%sort_macr(Glucose)&lt;/PRE&gt;&lt;P&gt;Thank you very much&lt;/P&gt;</description>
      <pubDate>Thu, 27 Sep 2018 09:20:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-Macro-Variable/m-p/499412#M132893</guid>
      <dc:creator>struppi1979</dc:creator>
      <dc:date>2018-09-27T09:20:11Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-Macro-Variable/m-p/499415#M132895</link>
      <description>&lt;P&gt;Use double quotes around macro variables otherwise they do not resolve:&lt;/P&gt;
&lt;PRE&gt;parameter in ("&amp;amp;variable.")&lt;/PRE&gt;
&lt;P&gt;And don't forget to always include the decimal place, you may get away with it, but best practice to always include it.&amp;nbsp; I do also wonder why you need a macro for this at all.&amp;nbsp; Its just a datastep where you have extracted one item, why not do all items in one datastep, no need for any macro code or the associated loops or merges needed later on because of that process.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Sep 2018 09:33:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-Macro-Variable/m-p/499415#M132895</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-09-27T09:33:37Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-Macro-Variable/m-p/499420#M132899</link>
      <description>&lt;P&gt;hey... this macro is made for more than one blood levels (hba1c, cholesterin ...)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;so it is much easier do do changes only once , and not on several parts in program.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but your solution does not work. &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt; the program still selects all blood levels&lt;/P&gt;</description>
      <pubDate>Thu, 27 Sep 2018 09:57:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-Macro-Variable/m-p/499420#M132899</guid>
      <dc:creator>struppi1979</dc:creator>
      <dc:date>2018-09-27T09:57:25Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-Macro-Variable/m-p/499422#M132900</link>
      <description>&lt;P&gt;Since you want to use &amp;amp;variable as part of SAS names, it can't be a list.&lt;/P&gt;
&lt;P&gt;So using&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;in ("&amp;amp;variable")&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is misleading and therefore bad.&lt;/P&gt;
&lt;P&gt;Use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;= "&amp;amp;variable"&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;instead.&lt;/P&gt;
&lt;P&gt;Next, run this code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let variable=Glucose;

DATA alle.&amp;amp;variable._T0 (keep =studie bmid bmdt_int bmankli_d bmankli_u abndat parameter wert Uhrzeit zeit minuten	&amp;amp;variable._ank_dat &amp;amp;variable._ank_wert &amp;amp;variable._Tag1_wert &amp;amp;variable._ank_comment &amp;amp;variable._Tag1_comment);

FORMAT 	&amp;amp;variable._ank_dat DDMMYY10.

	   	&amp;amp;variable._ank_wert &amp;amp;variable._Tag1_wert  $50.
	
	   	&amp;amp;variable._ank_comment &amp;amp;variable._Tag1_comment  $50.

		Uhrzeit HHMM5.
		minuten 4.;

SET alle.merge_ank_lab_1;

Uhrzeit=timepart(zeit);
minuten=INTCK('minute',bmankli_u,Uhrzeit);


if bmankli_d = abndat;

if wert not in('.','n.nwb.','neg','neg.');


if 0 &amp;lt;= minuten&amp;lt;=70 and not missing (bmankli_d) and not missing (bmankli_u) and parameter = "&amp;amp;variable."  then do; 
&amp;amp;variable._ank_dat=abndat;
&amp;amp;variable._ank_wert=wert;
&amp;amp;variable._ank_comment = 'Abnahme 0 bis 70 min nach Aufnahme';
end;

RUN;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and have a look at the log. Macro development must always start with working Base SAS code, so debug this until it works.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Sep 2018 10:12:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-Macro-Variable/m-p/499422#M132900</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-09-27T10:12:13Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-Macro-Variable/m-p/499423#M132901</link>
      <description>&lt;P&gt;And work on consistent visual formatting and a consistent coding style.&lt;/P&gt;
&lt;P&gt;Compare this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let variable=Glucose;

data alle.&amp;amp;variable._t0 (keep=
  studie bmid bmdt_int bmankli_d bmankli_u abndat parameter wert
  uhrzeit zeit minuten &amp;amp;variable._ank_dat &amp;amp;variable._ank_wert
  &amp;amp;variable._tag1_wert &amp;amp;variable._ank_comment &amp;amp;variable._tag1_comment
);
format
  &amp;amp;variable._ank_dat ddmmyy10.
  &amp;amp;variable._ank_wert
  &amp;amp;variable._tag1_wert
  &amp;amp;variable._ank_comment
  &amp;amp;variable._tag1_comment
    $50.
  uhrzeit hhmm5.
  minuten 4.
;
set alle.merge_ank_lab_1;
uhrzeit = timepart(zeit);
minuten = intck('minute',bmankli_u,uhrzeit);
if bmankli_d = abndat;
if wert not in('.','n.nwb.','neg','neg.');
if
  0 &amp;lt;= minuten &amp;lt;= 70 and not missing(bmankli_d)
  and not missing(bmankli_u) and parameter = "&amp;amp;variable."
then do; 
  &amp;amp;variable._ank_dat = abndat;
  &amp;amp;variable._ank_wert = wert;
  &amp;amp;variable._ank_comment = 'Abnahme 0 bis 70 min nach Aufnahme';
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;with your original code.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Sep 2018 10:16:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-Macro-Variable/m-p/499423#M132901</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-09-27T10:16:06Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-Macro-Variable/m-p/499426#M132902</link>
      <description>&lt;P&gt;"&lt;SPAN&gt;hey... this macro is made for more than one blood levels (hba1c, cholesterin ...)"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So?&amp;nbsp; If you have an LB domain dataset, then you can process all blood levels in one datastep, using the same code, no need to break anything out into individual tests?&amp;nbsp; If the condition changes based on param, then use an if block or a select block.&amp;nbsp; Macro is never needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In terms of your response, why would you expect it to return only a set amount of records, I cannot see from a glance anywhere where you restrict the data, e.g. a where clause, so of course it would return everything.&amp;nbsp; The only place its used is in:&lt;/P&gt;
&lt;PRE&gt;and parameter in ('&amp;amp;variable')&lt;/PRE&gt;
&lt;P&gt;But that doesn't conditionally output anything.&lt;/P&gt;
&lt;P&gt;As a note for future, stating "it doesn't work" will not get you much help back.&amp;nbsp; Need to see code, logs, test data in the form of a datastep.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Sep 2018 10:24:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-Macro-Variable/m-p/499426#M132902</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-09-27T10:24:06Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-Macro-Variable/m-p/499429#M132905</link>
      <description>&lt;P&gt;... solved.. this works fine , i should have a better look at the results...&amp;nbsp; Thanks to all&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;index(parameter,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;"&amp;amp;variable"&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;I had a mental error&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Sep 2018 10:45:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-Macro-Variable/m-p/499429#M132905</guid>
      <dc:creator>struppi1979</dc:creator>
      <dc:date>2018-09-27T10:45:13Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-Macro-Variable/m-p/499431#M132907</link>
      <description>&lt;P&gt;So parameter is actually a list of values, and &amp;amp;variable one of those? That would have been good to know from the start. That's why we always ask for properly presented example data, so we can follow Maxim 3.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Sep 2018 10:47:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-Macro-Variable/m-p/499431#M132907</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-09-27T10:47:44Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-Macro-Variable/m-p/499433#M132909</link>
      <description>&lt;P&gt;yes sorry... my mistake. &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Sep 2018 10:59:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-Macro-Variable/m-p/499433#M132909</guid>
      <dc:creator>struppi1979</dc:creator>
      <dc:date>2018-09-27T10:59:33Z</dc:date>
    </item>
  </channel>
</rss>

