<?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: My SAS variable is not resolving  before moving to next variable call when I am using two iterat in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/My-SAS-variable-is-not-resolving-before-moving-to-next-variable/m-p/921643#M362947</link>
    <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;I want to create a table name from macro variables I iterate through.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;Why?&amp;nbsp; What is the larger problem you are trying to solve and how does being able to generate dataset name in this way help?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;There are a lot of mistakes in that SAS code.&amp;nbsp; First let's clean up the setup part.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data things;
  input thing $6.;
cards;
auto
rv
boat
;

proc sql noprint;
select distinct thing 
  into :thing1-
  from things
;
%let nthings=&amp;amp;sqlobs;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;So now you have 3 macro variables named THING1, THING2 and THING3 and a fourth macro variable named NTHINGS which you could perhaps use to do something (what??).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Now let's cleanup your attempt to loop and build a token from the indexes and those macro variables.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Let's just write the generated string to the LOG so we can see what we get.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro thingy;
%do i=1 %to 2;
  %do j=1 %to &amp;amp;nthings;
    %put &amp;amp;=i &amp;amp;=J prefix_&amp;amp;&amp;amp;thing&amp;amp;j.._&amp;amp;i._suffix ;
  %end;
%end;
%mend thingy;
%thingy;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;Results:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;262  %macro thingy;
263  %do i=1 %to 2;
264    %do j=1 %to &amp;amp;nthings;
265      %put &amp;amp;=i &amp;amp;=j prefix_&amp;amp;&amp;amp;thing&amp;amp;j.._&amp;amp;i._suffix ;
266    %end;
267  %end;
268  %mend thingy;
269  %thingy;
I=1 J=1 prefix_auto_1_suffix
I=1 J=2 prefix_boat_1_suffix
I=1 J=3 prefix_rv_1_suffix
I=2 J=1 prefix_auto_2_suffix
I=2 J=2 prefix_boat_2_suffix
I=2 J=3 prefix_rv_2_suffix
&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;But why couldn't you just leave the value of THING in the actual variable?&amp;nbsp; What did you gain by moving them into macro variables?&amp;nbsp; Perhaps just passing in one value at a time?&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro thingy(thing);
%do i=1 %to 2;
    %put &amp;amp;=i prefix_&amp;amp;thing._&amp;amp;i._suffix ;
%end;
%mend thingy;

data _null_;
  set things;
  call execute(cats('%nrstr(%thingy)(',thing,')'));
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;Result&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;1   + %thingy(auto)
I=1 prefix_auto_1_suffix
I=2 prefix_auto_2_suffix
2   + %thingy(rv)
I=1 prefix_rv_1_suffix
I=2 prefix_rv_2_suffix
3   + %thingy(boat)
I=1 prefix_boat_1_suffix
I=2 prefix_boat_2_suffix
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 24 Mar 2024 21:06:52 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2024-03-24T21:06:52Z</dc:date>
    <item>
      <title>My SAS variable is not resolving  before moving to next variable call when I am using two iterators</title>
      <link>https://communities.sas.com/t5/SAS-Programming/My-SAS-variable-is-not-resolving-before-moving-to-next-variable/m-p/921641#M362945</link>
      <description>&lt;P&gt;I want to create a table name from macro variables I iterate through. I am running into a problem when the first macro call &amp;amp;&amp;amp;thing&amp;amp;i. does not resolve and SAS is trying to resolve the combined call. The first call &amp;amp;&amp;amp;thing&amp;amp;j. is resolving to &amp;amp;thing1. How do I have thing1 get resolved to: auto?&amp;nbsp;&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=""&gt;data things;
input thing $6.;
auto
rv
boat
;

proc SQL;
select distinct thing&amp;nbsp;
into :thing1-
from things;
quit;

macro thingy();
%do i %to %6;
%do j %to &amp;amp;sqlobs;
data temp;
set have.&amp;amp;&amp;amp;thing&amp;amp;j._&amp;amp;i.mo;
run;
%end;
%end;
%mend thingy;
%thingy()



&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 24 Mar 2024 20:36:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/My-SAS-variable-is-not-resolving-before-moving-to-next-variable/m-p/921641#M362945</guid>
      <dc:creator>KatWinSASland</dc:creator>
      <dc:date>2024-03-24T20:36:53Z</dc:date>
    </item>
    <item>
      <title>Re: My SAS variable is not resolving  before moving to next variable call when I am using two iterat</title>
      <link>https://communities.sas.com/t5/SAS-Programming/My-SAS-variable-is-not-resolving-before-moving-to-next-variable/m-p/921642#M362946</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;set have.&amp;amp;&amp;amp;thing&amp;amp;j._&amp;amp;i.mo;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After &amp;amp;j, try using two dots. (If that doesn't work, try three dots)&lt;/P&gt;</description>
      <pubDate>Sun, 24 Mar 2024 20:42:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/My-SAS-variable-is-not-resolving-before-moving-to-next-variable/m-p/921642#M362946</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-03-24T20:42:09Z</dc:date>
    </item>
    <item>
      <title>Re: My SAS variable is not resolving  before moving to next variable call when I am using two iterat</title>
      <link>https://communities.sas.com/t5/SAS-Programming/My-SAS-variable-is-not-resolving-before-moving-to-next-variable/m-p/921643#M362947</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;I want to create a table name from macro variables I iterate through.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;Why?&amp;nbsp; What is the larger problem you are trying to solve and how does being able to generate dataset name in this way help?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;There are a lot of mistakes in that SAS code.&amp;nbsp; First let's clean up the setup part.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data things;
  input thing $6.;
cards;
auto
rv
boat
;

proc sql noprint;
select distinct thing 
  into :thing1-
  from things
;
%let nthings=&amp;amp;sqlobs;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;So now you have 3 macro variables named THING1, THING2 and THING3 and a fourth macro variable named NTHINGS which you could perhaps use to do something (what??).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Now let's cleanup your attempt to loop and build a token from the indexes and those macro variables.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Let's just write the generated string to the LOG so we can see what we get.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro thingy;
%do i=1 %to 2;
  %do j=1 %to &amp;amp;nthings;
    %put &amp;amp;=i &amp;amp;=J prefix_&amp;amp;&amp;amp;thing&amp;amp;j.._&amp;amp;i._suffix ;
  %end;
%end;
%mend thingy;
%thingy;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;Results:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;262  %macro thingy;
263  %do i=1 %to 2;
264    %do j=1 %to &amp;amp;nthings;
265      %put &amp;amp;=i &amp;amp;=j prefix_&amp;amp;&amp;amp;thing&amp;amp;j.._&amp;amp;i._suffix ;
266    %end;
267  %end;
268  %mend thingy;
269  %thingy;
I=1 J=1 prefix_auto_1_suffix
I=1 J=2 prefix_boat_1_suffix
I=1 J=3 prefix_rv_1_suffix
I=2 J=1 prefix_auto_2_suffix
I=2 J=2 prefix_boat_2_suffix
I=2 J=3 prefix_rv_2_suffix
&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;But why couldn't you just leave the value of THING in the actual variable?&amp;nbsp; What did you gain by moving them into macro variables?&amp;nbsp; Perhaps just passing in one value at a time?&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro thingy(thing);
%do i=1 %to 2;
    %put &amp;amp;=i prefix_&amp;amp;thing._&amp;amp;i._suffix ;
%end;
%mend thingy;

data _null_;
  set things;
  call execute(cats('%nrstr(%thingy)(',thing,')'));
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;Result&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;1   + %thingy(auto)
I=1 prefix_auto_1_suffix
I=2 prefix_auto_2_suffix
2   + %thingy(rv)
I=1 prefix_rv_1_suffix
I=2 prefix_rv_2_suffix
3   + %thingy(boat)
I=1 prefix_boat_1_suffix
I=2 prefix_boat_2_suffix
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 24 Mar 2024 21:06:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/My-SAS-variable-is-not-resolving-before-moving-to-next-variable/m-p/921643#M362947</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-03-24T21:06:52Z</dc:date>
    </item>
    <item>
      <title>Re: My SAS variable is not resolving  before moving to next variable call when I am using two iterat</title>
      <link>https://communities.sas.com/t5/SAS-Programming/My-SAS-variable-is-not-resolving-before-moving-to-next-variable/m-p/921646#M362948</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;said:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;So now you have 3 macro variables named THING1, THING2 and THING3 and a fourth macro variable named NTHINGS which you could perhaps use to do something (what??).&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I'm sure this was in a Dr. Seuss book I once read. I didn't know he was writing about SAS macros!&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;But good question!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 24 Mar 2024 23:24:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/My-SAS-variable-is-not-resolving-before-moving-to-next-variable/m-p/921646#M362948</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-03-24T23:24:21Z</dc:date>
    </item>
  </channel>
</rss>

