<?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: Using a do-loop with call symputx in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-a-do-loop-with-call-symputx/m-p/788453#M252100</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/388382"&gt;@mgrasmussen&lt;/a&gt;&amp;nbsp;You also don't need all this %do looping.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro extract;

  data _null_;
    set quartiles;
    if not missing(id);

    call symputx(cats('p_25_',id),p_25);
    call symputx(cats('p_50_',id),p_50);
    call symputx(cats('p_75_',id),p_75);
  run;

  %put &amp;amp;p_25_1;
  %put &amp;amp;p_50_1;
  %put &amp;amp;p_75_1;
  %put &amp;amp;p_25_2;
  %put &amp;amp;p_50_2;
  %put &amp;amp;p_75_2;
  %put &amp;amp;p_25_3;
  %put &amp;amp;p_50_3;
  %put &amp;amp;p_75_3;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 05 Jan 2022 13:01:12 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2022-01-05T13:01:12Z</dc:date>
    <item>
      <title>Using a do-loop with call symputx</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-do-loop-with-call-symputx/m-p/788443#M252094</link>
      <description>&lt;P&gt;Dear SAS expert&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to use a do-loop to save certain values as macro variables. The purpose is to ease coding. I want to use call symputx to save certain values of a dataset in macro variables. Below is some simplified code to show the issue that I have in the coding. According to the log all macro variables resolve to missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can someone pinpoint where my code is incorrect? Thank you&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;input id value;&lt;BR /&gt;datalines;&lt;BR /&gt;1 15&lt;BR /&gt;1 22&lt;BR /&gt;1 31&lt;BR /&gt;1 4&lt;BR /&gt;2 10&lt;BR /&gt;2 0.5&lt;BR /&gt;3 6&lt;BR /&gt;3 2&lt;BR /&gt;3 7&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc means data=have noprint;&lt;BR /&gt;class id;&lt;BR /&gt;output out=quartiles(drop=_type_ _freq_)n=n p25=p_25 p50=p_50 p75=p_75;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro extract;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;%do jump=1 %to 3;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;BR /&gt;set have;&lt;BR /&gt;if id=&amp;amp;jump then call symputx("p_25_&amp;amp;jump.",p_25); &lt;BR /&gt;if id=&amp;amp;jump then call symputx("p_50_&amp;amp;jump.",p_50);&lt;BR /&gt;if id=&amp;amp;jump then call symputx("p_75_&amp;amp;jump.",p_75);&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%put &amp;amp;p_25_1;&lt;BR /&gt;%put &amp;amp;p_50_1;&lt;BR /&gt;%put &amp;amp;p_75_1;&lt;BR /&gt;%put &amp;amp;p_25_2;&lt;BR /&gt;%put &amp;amp;p_50_2;&lt;BR /&gt;%put &amp;amp;p_75_2;&lt;BR /&gt;%put &amp;amp;p_25_3;&lt;BR /&gt;%put &amp;amp;p_50_3;&lt;BR /&gt;%put &amp;amp;p_75_3;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%mend;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%extract;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jan 2022 12:29:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-do-loop-with-call-symputx/m-p/788443#M252094</guid>
      <dc:creator>mgrasmussen</dc:creator>
      <dc:date>2022-01-05T12:29:58Z</dc:date>
    </item>
    <item>
      <title>Re: Using a do-loop with call symputx</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-do-loop-with-call-symputx/m-p/788446#M252096</link>
      <description>&lt;P&gt;It always helps to write code that works without macro elements before you create a macro, but very few people follow that advice. If you had followed that advice, you would probably have discovered the problem, which is not a macro problem at all. So I suggest you follow this advice.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's (a portion of) your code without macros. Can you spot why it doesn't work? If so, fix it and then a similar fix will lead to your macro working.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set have;
if id=1 then call symputx("p_25_1",p_25);
if id=1 then call symputx("p_50_1",p_50);
if id=1 then call symputx("p_75_1",p_75);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jan 2022 12:40:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-do-loop-with-call-symputx/m-p/788446#M252096</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-01-05T12:40:23Z</dc:date>
    </item>
    <item>
      <title>Re: Using a do-loop with call symputx</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-do-loop-with-call-symputx/m-p/788450#M252098</link>
      <description>&lt;P&gt;Dear PaigeMiller&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for the reply.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I truly cannot spot the issue, but based on your answer, it must be something simple.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jan 2022 12:52:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-do-loop-with-call-symputx/m-p/788450#M252098</guid>
      <dc:creator>mgrasmussen</dc:creator>
      <dc:date>2022-01-05T12:52:04Z</dc:date>
    </item>
    <item>
      <title>Re: Using a do-loop with call symputx</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-do-loop-with-call-symputx/m-p/788451#M252099</link>
      <description>&lt;P&gt;Right. The set command. I am referencing the wrong dataset.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jan 2022 12:54:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-do-loop-with-call-symputx/m-p/788451#M252099</guid>
      <dc:creator>mgrasmussen</dc:creator>
      <dc:date>2022-01-05T12:54:13Z</dc:date>
    </item>
    <item>
      <title>Re: Using a do-loop with call symputx</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-do-loop-with-call-symputx/m-p/788453#M252100</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/388382"&gt;@mgrasmussen&lt;/a&gt;&amp;nbsp;You also don't need all this %do looping.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro extract;

  data _null_;
    set quartiles;
    if not missing(id);

    call symputx(cats('p_25_',id),p_25);
    call symputx(cats('p_50_',id),p_50);
    call symputx(cats('p_75_',id),p_75);
  run;

  %put &amp;amp;p_25_1;
  %put &amp;amp;p_50_1;
  %put &amp;amp;p_75_1;
  %put &amp;amp;p_25_2;
  %put &amp;amp;p_50_2;
  %put &amp;amp;p_75_2;
  %put &amp;amp;p_25_3;
  %put &amp;amp;p_50_3;
  %put &amp;amp;p_75_3;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Jan 2022 13:01:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-do-loop-with-call-symputx/m-p/788453#M252100</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-01-05T13:01:12Z</dc:date>
    </item>
    <item>
      <title>Re: Using a do-loop with call symputx</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-do-loop-with-call-symputx/m-p/788454#M252101</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/388382"&gt;@mgrasmussen&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Awesome. Good work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now here is how to do this without a %DO loop&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set quartiles(where=(not missing(id)));
call symputx(cats("p_25_",id),p_25);
call symputx(cats("p_50_",id),p_50);
call symputx(cats("p_75_",id),p_75);
run;

%put &amp;amp;p_25_1;
%put &amp;amp;p_50_1;
%put &amp;amp;p_75_1;
%put &amp;amp;p_25_2;
%put &amp;amp;p_50_2;
%put &amp;amp;p_75_2;
%put &amp;amp;p_25_3;
%put &amp;amp;p_50_3;
%put &amp;amp;p_75_3;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Jan 2022 13:02:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-do-loop-with-call-symputx/m-p/788454#M252101</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-01-05T13:02:10Z</dc:date>
    </item>
    <item>
      <title>Re: Using a do-loop with call symputx</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-do-loop-with-call-symputx/m-p/788457#M252102</link>
      <description>&lt;P&gt;Right. Interesting code. Does look more "smooth" than mine with the do loop. Thanks a bunch!&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jan 2022 13:08:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-do-loop-with-call-symputx/m-p/788457#M252102</guid>
      <dc:creator>mgrasmussen</dc:creator>
      <dc:date>2022-01-05T13:08:38Z</dc:date>
    </item>
    <item>
      <title>Re: Using a do-loop with call symputx</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-do-loop-with-call-symputx/m-p/788459#M252103</link>
      <description>&lt;P&gt;Why are you putting all of the P value into macro variables?&lt;/P&gt;
&lt;P&gt;What are you going to do with them?&amp;nbsp; If you need to use them in further calculations then leave them as actual variables instead and avoid the loss of precision that will occur if you force the values into text strings to be stored into macro variables.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jan 2022 13:31:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-do-loop-with-call-symputx/m-p/788459#M252103</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-01-05T13:31:22Z</dc:date>
    </item>
    <item>
      <title>Re: Using a do-loop with call symputx</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-do-loop-with-call-symputx/m-p/788461#M252104</link>
      <description>&lt;P&gt;Excellent point by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data set QUARTILES could be used in most cases instead of these macro variables, eliminating any potential loss of precision, and in fact eliminating the need to create the macro variables in the first place. So, how will these quartiles be used?&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jan 2022 13:36:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-do-loop-with-call-symputx/m-p/788461#M252104</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-01-05T13:36:22Z</dc:date>
    </item>
    <item>
      <title>Re: Using a do-loop with call symputx</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-do-loop-with-call-symputx/m-p/788617#M252181</link>
      <description>&lt;P&gt;Thanks for the input, Tom and PaigeMiller. I appreciate it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To make a long story short, I calculate quartiles for certain subgroups in a large population, which work as reference quartiles for a subgroup which is nested within the abovementioned population subgroup. Specifically, I calculate the "overall" quartiles and then I use these to categorize a subgroup nested within the overall subgroup. More specifically, I take a general population, compute quartiles within certain age groups, and then categorize a diseased population according to these quartiles within the same age groups for the diseased population. Moreover, I do this for each year (seperate datasets). Therefore, my intuition tells me that the use of macro variables is reasonable, but I would be happy to hear whether or not you agree.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jan 2022 09:33:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-do-loop-with-call-symputx/m-p/788617#M252181</guid>
      <dc:creator>mgrasmussen</dc:creator>
      <dc:date>2022-01-06T09:33:16Z</dc:date>
    </item>
  </channel>
</rss>

