<?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: Fixing macro values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Fixing-macro-values/m-p/968286#M376518</link>
    <description>&lt;P&gt;I see now.&amp;nbsp; &amp;nbsp;You have mistakenly used:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; %put brands=&amp;amp;;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;instead of:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; %put &amp;amp;=brands;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Your %PUT statement does not reference a macro variable.&lt;/P&gt;</description>
    <pubDate>Thu, 05 Jun 2025 17:14:57 GMT</pubDate>
    <dc:creator>Quentin</dc:creator>
    <dc:date>2025-06-05T17:14:57Z</dc:date>
    <item>
      <title>Fixing macro values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fixing-macro-values/m-p/968282#M376514</link>
      <description>&lt;P&gt;I'm trying to select values on a data set based on an extraction for search variables from another dataset.&amp;nbsp; &amp;nbsp;However, the macro doesn't retrieve any values (see rows 30-50.&amp;nbsp; &amp;nbsp;When I copy the macro-generated query from the log, it still doesn't work (see rows 51-57).&amp;nbsp; &amp;nbsp;However, when I when run it again after changing the where statement to single quotes (rows 58-66), it does work.&amp;nbsp; &amp;nbsp;However, I need double quotes in the macro code.&amp;nbsp; &amp;nbsp;What gives?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;30 %macro importer;&lt;BR /&gt;31 /*extract values form 16th row of dataset*/&lt;BR /&gt;32 %let i=16;&lt;BR /&gt;33 data _null_;&lt;BR /&gt;34 set contraceptive_ingredient(firstobs=&amp;amp;i. obs=&amp;amp;i.);&lt;BR /&gt;35 call symputx('Cont_cat', 'Contraceptive Product Category'n);&lt;BR /&gt;36 call symputx('Act_Ing','Active Ingredients'n);&lt;BR /&gt;37 run;&lt;BR /&gt;38 %PUT &amp;amp;i &amp;amp;Cont_cat &amp;amp;Act_Ing;&lt;BR /&gt;39&lt;BR /&gt;40 /*Use selected values to create a macro array from larger dataset*/&lt;BR /&gt;41 proc sql noprint;&lt;BR /&gt;42 select distinct brand into: brands separated by ', '&lt;BR /&gt;43 from sel_drugs&lt;BR /&gt;44 where cont_cat="&amp;amp;Cont_cat"&lt;BR /&gt;45 and Act_Ing="&amp;amp;Act_Ing";&lt;BR /&gt;46 %put brands=&amp;amp;;&lt;BR /&gt;47&lt;BR /&gt;48 %mend;&lt;BR /&gt;49 %importer&lt;BR /&gt;MPRINT(IMPORTER): data _null_;&lt;BR /&gt;MPRINT(IMPORTER): set contraceptive_ingredient(firstobs=16 obs=16);&lt;BR /&gt;MPRINT(IMPORTER): call symputx('Cont_cat', 'Contraceptive Product Category'n);&lt;BR /&gt;MPRINT(IMPORTER): call symputx('Act_Ing','Active Ingredients'n);&lt;BR /&gt;MPRINT(IMPORTER): run;&lt;/P&gt;&lt;P&gt;NOTE: There were 1 observations read from the data set WORK.CONTRACEPTIVE_INGREDIENT.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;2 The SAS System 11:36 Thursday, June 5, 2025&lt;/P&gt;&lt;P&gt;real time 0.01 seconds&lt;BR /&gt;cpu time 0.01 seconds&lt;/P&gt;&lt;P&gt;16 IUD (intrauterine device)/IUS (intrauterine system) without hormone (copper) LEVONORGESTREL&lt;BR /&gt;MPRINT(IMPORTER): proc sql noprint;&lt;BR /&gt;MPRINT(IMPORTER): select distinct brand into: brands separated by ', ' from sel_drugs where cont_cat="IUD (intrauterine&lt;BR /&gt;device)/IUS (intrauterine system) without hormone (copper)" and Act_Ing="LEVONORGESTREL";&lt;BR /&gt;brands=&amp;amp;&lt;BR /&gt;50&lt;BR /&gt;51 /*copied from log*/&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;real time 0.02 seconds&lt;BR /&gt;cpu time 0.03 seconds&lt;BR /&gt;&lt;BR /&gt;52 proc sql noprint;&lt;/P&gt;&lt;P&gt;53 select distinct brand into: brands separated by ', ' from sel_drugs where cont_cat="IUD (intrauterine&lt;BR /&gt;54 device)/IUS (intrauterine system) without hormone (copper)" and Act_Ing="LEVONORGESTREL";&lt;BR /&gt;55 quit;&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;real time 0.02 seconds&lt;BR /&gt;cpu time 0.03 seconds&lt;/P&gt;&lt;P&gt;56 %put brands=&amp;amp;;&lt;BR /&gt;brands=&amp;amp;&lt;BR /&gt;57&lt;BR /&gt;58 /*changing double to single quotes*/&lt;BR /&gt;59 proc sql;&lt;BR /&gt;60 select distinct brand into: brands separated by ', ' from sel_drugs where cont_cat='IUD (intrauterine&lt;BR /&gt;61 device)/IUS (intrauterine system) without hormone (copper)' and Act_Ing='LEVONORGESTREL';&lt;BR /&gt;62 quit;&lt;BR /&gt;NOTE: The PROCEDURE SQL printed page 1.&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;real time 0.04 seconds&lt;BR /&gt;cpu time 0.03 seconds&lt;/P&gt;&lt;P&gt;63 %put &amp;amp;Brands&lt;BR /&gt;64&lt;BR /&gt;65&lt;BR /&gt;66 GOPTIONS NOACCESSIBLE;&lt;BR /&gt;KYLEENA, LILETTA, MIRENA, SKYLA&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jun 2025 17:03:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fixing-macro-values/m-p/968282#M376514</guid>
      <dc:creator>Batman</dc:creator>
      <dc:date>2025-06-05T17:03:43Z</dc:date>
    </item>
    <item>
      <title>Re: Fixing macro values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fixing-macro-values/m-p/968283#M376515</link>
      <description>&lt;P&gt;Please paste the log into the "code box" that appears when you click on the &amp;lt;/&amp;gt; icon here. (And paste from the log window; do not paste from your message above). Using the "code box" aligns the text properly and enables us to see problems more easily. So doing this helps us, which helps you too.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PaigeMiller_0-1715196634946.png" style="width: 859px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96351i414DE7EE2D1B5DE6/image-size/large?v=v2&amp;amp;px=999" role="button" title="PaigeMiller_0-1715196634946.png" alt="PaigeMiller_0-1715196634946.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jun 2025 17:10:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fixing-macro-values/m-p/968283#M376515</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-06-05T17:10:33Z</dc:date>
    </item>
    <item>
      <title>Re: Fixing macro values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fixing-macro-values/m-p/968284#M376516</link>
      <description>&lt;PRE&gt;30         %macro importer;
31         /*extract values form 16th row of dataset*/
32         %let i=16;
33         data _null_;
34          set contraceptive_ingredient(firstobs=&amp;amp;i. obs=&amp;amp;i.);
35          call symputx('Cont_cat', 'Contraceptive Product Category'n);
36          call symputx('Act_Ing','Active Ingredients'n);
37         run;
38         %PUT &amp;amp;i &amp;amp;Cont_cat &amp;amp;Act_Ing;
39         
40         /*Use selected values to create a macro array from larger dataset*/
41         proc sql noprint;
42         	select distinct brand into: brands separated by ', '
43         	from sel_drugs
44         	where cont_cat="&amp;amp;Cont_cat"
45         	and Act_Ing="&amp;amp;Act_Ing";
46         %put brands=&amp;amp;;
47         
48         %mend;
49         %importer
MPRINT(IMPORTER):   data _null_;
MPRINT(IMPORTER):   set contraceptive_ingredient(firstobs=16 obs=16);
MPRINT(IMPORTER):   call symputx('Cont_cat', 'Contraceptive Product Category'n);
MPRINT(IMPORTER):   call symputx('Act_Ing','Active Ingredients'n);
MPRINT(IMPORTER):   run;

NOTE: There were 1 observations read from the data set WORK.CONTRACEPTIVE_INGREDIENT.
NOTE: DATA statement used (Total process time):
2                                                          The SAS System                               11:36 Thursday, June 5, 2025

      real time           0.01 seconds
      cpu time            0.01 seconds
      

16 IUD (intrauterine device)/IUS (intrauterine system) without hormone (copper) LEVONORGESTREL
MPRINT(IMPORTER):   proc sql noprint;
MPRINT(IMPORTER):   select distinct brand into: brands separated by ', ' from sel_drugs where cont_cat="IUD (intrauterine 
device)/IUS (intrauterine system) without hormone (copper)" and Act_Ing="LEVONORGESTREL";
brands=&amp;amp;
50         
51         /*copied from log*/
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.02 seconds
      cpu time            0.03 seconds
      
52         proc sql noprint;

53         select distinct brand into: brands separated by ', ' from sel_drugs where cont_cat="IUD (intrauterine
54         device)/IUS (intrauterine system) without hormone (copper)" and Act_Ing="LEVONORGESTREL";
55         quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.02 seconds
      cpu time            0.03 seconds
      

56         %put brands=&amp;amp;;
brands=&amp;amp;
57         
58         /*changing double to single quotes*/
59         proc sql;
60         select distinct brand into: brands separated by ', ' from sel_drugs where cont_cat='IUD (intrauterine
61         device)/IUS (intrauterine system) without hormone (copper)' and Act_Ing='LEVONORGESTREL';
62         quit;
NOTE: The PROCEDURE SQL printed page 1.
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.04 seconds
      cpu time            0.03 seconds
      

63         %put &amp;amp;Brands
64         
65         
66         GOPTIONS NOACCESSIBLE;
KYLEENA, LILETTA, MIRENA, SKYLA &lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Jun 2025 17:11:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fixing-macro-values/m-p/968284#M376516</guid>
      <dc:creator>Batman</dc:creator>
      <dc:date>2025-06-05T17:11:31Z</dc:date>
    </item>
    <item>
      <title>Re: Fixing macro values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fixing-macro-values/m-p/968285#M376517</link>
      <description>&lt;P&gt;I'm confused.&amp;nbsp; Are you saying you get different results from running the below two bits of code, one with double quotes and one with single quotes?&amp;nbsp; That would be very surprising.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*double quotes;
proc sql noprint;
  select distinct brand into: brands separated by ', ' 
  from sel_drugs 
  where cont_cat="IUD (intrauterine device)/IUS (intrauterine system) without hormone (copper)" and Act_Ing="LEVONORGESTREL"
;
%put &amp;amp;=brands;


*single quotes;
proc sql noprint;
  select distinct brand into: brands separated by ', ' 
  from sel_drugs 
  where cont_cat='IUD (intrauterine device)/IUS (intrauterine system) without hormone (copper)' and Act_Ing='LEVONORGESTREL'
;
%put &amp;amp;=brands;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note when posting code, please click the "running man" insert SAS code button and paste your code into that window.&amp;nbsp; It formats the code as code rather than as part of the text.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jun 2025 17:12:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fixing-macro-values/m-p/968285#M376517</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2025-06-05T17:12:52Z</dc:date>
    </item>
    <item>
      <title>Re: Fixing macro values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fixing-macro-values/m-p/968286#M376518</link>
      <description>&lt;P&gt;I see now.&amp;nbsp; &amp;nbsp;You have mistakenly used:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; %put brands=&amp;amp;;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;instead of:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; %put &amp;amp;=brands;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Your %PUT statement does not reference a macro variable.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jun 2025 17:14:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fixing-macro-values/m-p/968286#M376518</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2025-06-05T17:14:57Z</dc:date>
    </item>
    <item>
      <title>Re: Fixing macro values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fixing-macro-values/m-p/968287#M376519</link>
      <description>&lt;P&gt;Ugh, yes, thanks&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jun 2025 17:18:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fixing-macro-values/m-p/968287#M376519</guid>
      <dc:creator>Batman</dc:creator>
      <dc:date>2025-06-05T17:18:01Z</dc:date>
    </item>
  </channel>
</rss>

