<?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: Get a value from a table and set it to be a numeric number for later reference. in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Get-a-value-from-a-table-and-set-it-to-be-a-numeric-number-for/m-p/765790#M30587</link>
    <description>&lt;P&gt;I don't understand what data you have or what you are trying to do.&lt;/P&gt;
&lt;P&gt;Please explain what you are trying to do first.&amp;nbsp; Before showing how you are trying to do it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want make 9 copies of the same data why use macro loops or even multiple data steps?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data exploded;
  set delta;
  do offset = 1 to 9;
     New_n_quarter = offset + n_quarter;
     New_gdp_base1 = gdp_base1 + delta_GDP * offset ;
     New_RTO_base1 = RTO_base1 + delta_RTO * offset ;
     New_ICR_base1 = ICR_base1 + delta_ICR * offset ;
     New_BCG_base1 = BCG_base1 + delta_BCG * offset ;
     output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;As to subject line. I assume by table you mean a SAS dataset and not a table you want to in your written report.&lt;/P&gt;
&lt;P&gt;What does the dataset have in it?&amp;nbsp; What do you want to use that information for?&lt;/P&gt;
&lt;P&gt;What do you mean by a "numeric number"?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In general if you want to use a value from a dataset then include that dataset into your calculations.&amp;nbsp; For example you created a dataset with the MEAN and STD of a variable you could re-combine it with the original dataset to calculate a ZSCORE like this.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   if n=1 then set mean_std;
   set have;
   zscore = (var- mean) / std ;
run;
   &lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 03 Sep 2021 03:00:30 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-09-03T03:00:30Z</dc:date>
    <item>
      <title>Get a value from a table and set it to be a numeric number for later reference.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Get-a-value-from-a-table-and-set-it-to-be-a-numeric-number-for/m-p/765726#M30582</link>
      <description>&lt;P&gt;Hi mates,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am new SAS user. I am trying to get a value from a table and allocate it into a variable for later using but don't know how to do it. Just wonder if you guys can help me with that. For example. Here I would like to get N_miss value (=9) from table N_miss and allocate this value to a variable called n_extent. Thanks for your help!&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="phongpham_0-1630613962028.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/63251i42BC52967D146B30/image-size/medium?v=v2&amp;amp;px=400" role="button" title="phongpham_0-1630613962028.png" alt="phongpham_0-1630613962028.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Sep 2021 20:21:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Get-a-value-from-a-table-and-set-it-to-be-a-numeric-number-for/m-p/765726#M30582</guid>
      <dc:creator>phongpham</dc:creator>
      <dc:date>2021-09-02T20:21:10Z</dc:date>
    </item>
    <item>
      <title>Re: Get a value from a table and set it to be a numeric number for later reference.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Get-a-value-from-a-table-and-set-it-to-be-a-numeric-number-for/m-p/765732#M30583</link>
      <description>&lt;P&gt;FYI, I will need reference for a loop like this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="phongpham_0-1630614453811.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/63252iA14587A4C6ABAB1D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="phongpham_0-1630614453811.png" alt="phongpham_0-1630614453811.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Sep 2021 20:27:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Get-a-value-from-a-table-and-set-it-to-be-a-numeric-number-for/m-p/765732#M30583</guid>
      <dc:creator>phongpham</dc:creator>
      <dc:date>2021-09-02T20:27:47Z</dc:date>
    </item>
    <item>
      <title>Re: Get a value from a table and set it to be a numeric number for later reference.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Get-a-value-from-a-table-and-set-it-to-be-a-numeric-number-for/m-p/765733#M30584</link>
      <description>&lt;P&gt;Please place code in either a text box, opened with the &amp;lt;/&amp;gt; icon, or a code box, opened with the "running man" icon instead of pictures. With text we can edit your text or copy and paste into an editor and run or modify the code to create a working solution. Not so much with pictures and as the day goes on I am much less likely to completely retype code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Next, what does your data set Delta or N_miss look like? And with those values in mind, what value do you expect to place into that do loop?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Almost certainly the solution will involve CALL SYMPUTX but if your data set Delta has more than one record which one do you want?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, it is poor technique to just have a macro variable appear in the middle of code. It is better practice to make such things parameters for the macro so some one with access to the macro code knows where the value comes from.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And last, if the only thing you use that macro for is to combine data sets with numbers you do not need a macro loop at all.&lt;/P&gt;
&lt;PRE&gt;Data delta_final;
   set delta1 - delta9;
run;&lt;/PRE&gt;
&lt;P&gt;for example uses a data set list and will combine delta1, delta2, delta3 , ...,delta9.&lt;/P&gt;
&lt;P&gt;So if you have macro variable with the number, which we go back to that question about what is in the N_miss data set, you would use&lt;/P&gt;
&lt;PRE&gt;Data delta_final;
   set delta1 - delta&amp;amp;n_miss. ;
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Sep 2021 20:42:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Get-a-value-from-a-table-and-set-it-to-be-a-numeric-number-for/m-p/765733#M30584</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-09-02T20:42:36Z</dc:date>
    </item>
    <item>
      <title>Re: Get a value from a table and set it to be a numeric number for later reference.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Get-a-value-from-a-table-and-set-it-to-be-a-numeric-number-for/m-p/765768#M30585</link>
      <description>&lt;P&gt;Hi mate,&lt;/P&gt;&lt;P&gt;Thanks for your quick reply and sorry for not put the code on the code tag. Just the first time I post here, so did not pay attention to it.&lt;/P&gt;&lt;P&gt;I attach here Delta file and the code I produced for your reference.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;PRE&gt;%macro loop (n=);
data delta_&amp;amp;n.;
set delta;
N_quarter =  %eval(&amp;amp;n.) + N_quarter;
gdp_base1 = gdp_base1 + delta_GDP * %eval(&amp;amp;n.);
RTO_base1 = RTO_base1 + delta_RTO * %eval(&amp;amp;n.);
ICR_base1 = ICR_base1 + delta_ICR * %eval(&amp;amp;n.);
BCG_base1 = BCG_base1 + delta_BCG * %eval(&amp;amp;n.);
run;
%mend;

data N_miss (keep=N_miss);
set delta;
run;

/* %let n_miss = 9; */


%macro extrapolate_forecast;
%do i = 1 %to 9; /* need to think how to add 9 here from N_miss */
	%loop (n=&amp;amp;i.);
%end;

data delta_final;
 set %do j = 1 %to 9;
	delta_&amp;amp;j.
	%end;
;
run;
%mend;

%extrapolate_forecast;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Sep 2021 23:14:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Get-a-value-from-a-table-and-set-it-to-be-a-numeric-number-for/m-p/765768#M30585</guid>
      <dc:creator>phongpham</dc:creator>
      <dc:date>2021-09-02T23:14:24Z</dc:date>
    </item>
    <item>
      <title>Re: Get a value from a table and set it to be a numeric number for later reference.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Get-a-value-from-a-table-and-set-it-to-be-a-numeric-number-for/m-p/765778#M30586</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro loop (n=);
data delta_&amp;amp;n.;
set delta;
N_quarter =  &amp;amp;n. + N_quarter;
gdp_base1 = gdp_base1 + delta_GDP *&amp;amp;n.;
RTO_base1 = RTO_base1 + delta_RTO *&amp;amp;n.;
ICR_base1 = ICR_base1 + delta_ICR *&amp;amp;n.;
BCG_base1 = BCG_base1 + delta_BCG *&amp;amp;n.;
run;
%mend;


%macro extrapolate_forecast(n_miss=);
%do i = 1 %to &amp;amp;n_miss; /* need to think how to add 9 here from N_miss */
	%loop (n=&amp;amp;i.);
%end;

data delta_final;
 set %do j = 1 %to 9;
	delta_&amp;amp;j.
	%end;
;
run;
%mend;

data N_miss (keep=N_miss);
set delta;
call execute(catt('%extrapolate_forecast(n_miss = ', 
                     n_miss, 
                     ');')
                    )
                      
run;




&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That being said, I think using shortcut references as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;suggest is more efficient. If you have unique prefixes this becomes trivial.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a reference that illustrates how to refer to variables and datasets in a short cut list:&lt;BR /&gt;&lt;A href="https://blogs.sas.com/content/iml/2018/05/29/6-easy-ways-to-specify-a-list-of-variables-in-sas.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2018/05/29/6-easy-ways-to-specify-a-list-of-variables-in-sas.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And I highly suggest using CALL EXECUTE for macro looping/calling instead of macro loops. It makes things much cleaner, easier to debug and maintain which are huge wins IMO. Looking closely at your code though, I really do wonder if arrays are not the correct answer here instead....but it's your program &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;UCLA introductory tutorial on macro variables and macros&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Tutorial on converting a working program to a macro&lt;BR /&gt;This method is pretty robust and helps prevent errors and makes it much easier to debug your code. Obviously biased, because I wrote it &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;A href="https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md" target="_blank"&gt;https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Examples of common macro usage&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Appendix/ta-p/291716" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Appendix/ta-p/291716&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Sep 2021 00:15:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Get-a-value-from-a-table-and-set-it-to-be-a-numeric-number-for/m-p/765778#M30586</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-09-03T00:15:35Z</dc:date>
    </item>
    <item>
      <title>Re: Get a value from a table and set it to be a numeric number for later reference.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Get-a-value-from-a-table-and-set-it-to-be-a-numeric-number-for/m-p/765790#M30587</link>
      <description>&lt;P&gt;I don't understand what data you have or what you are trying to do.&lt;/P&gt;
&lt;P&gt;Please explain what you are trying to do first.&amp;nbsp; Before showing how you are trying to do it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want make 9 copies of the same data why use macro loops or even multiple data steps?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data exploded;
  set delta;
  do offset = 1 to 9;
     New_n_quarter = offset + n_quarter;
     New_gdp_base1 = gdp_base1 + delta_GDP * offset ;
     New_RTO_base1 = RTO_base1 + delta_RTO * offset ;
     New_ICR_base1 = ICR_base1 + delta_ICR * offset ;
     New_BCG_base1 = BCG_base1 + delta_BCG * offset ;
     output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;As to subject line. I assume by table you mean a SAS dataset and not a table you want to in your written report.&lt;/P&gt;
&lt;P&gt;What does the dataset have in it?&amp;nbsp; What do you want to use that information for?&lt;/P&gt;
&lt;P&gt;What do you mean by a "numeric number"?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In general if you want to use a value from a dataset then include that dataset into your calculations.&amp;nbsp; For example you created a dataset with the MEAN and STD of a variable you could re-combine it with the original dataset to calculate a ZSCORE like this.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   if n=1 then set mean_std;
   set have;
   zscore = (var- mean) / std ;
run;
   &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 Sep 2021 03:00:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Get-a-value-from-a-table-and-set-it-to-be-a-numeric-number-for/m-p/765790#M30587</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-09-03T03:00:30Z</dc:date>
    </item>
    <item>
      <title>Re: Get a value from a table and set it to be a numeric number for later reference.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Get-a-value-from-a-table-and-set-it-to-be-a-numeric-number-for/m-p/765925#M30591</link>
      <description>&lt;P&gt;Hi Reeza,&lt;/P&gt;&lt;P&gt;Thanks for your solution!&lt;/P&gt;&lt;P&gt;It works for me. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;As I mentioned in my post, I am new to SAS, so there are tons of things to learn.&lt;/P&gt;&lt;P&gt;Very much appreciate your help and your resource.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Phong Pham&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Sep 2021 20:02:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Get-a-value-from-a-table-and-set-it-to-be-a-numeric-number-for/m-p/765925#M30591</guid>
      <dc:creator>phongpham</dc:creator>
      <dc:date>2021-09-03T20:02:23Z</dc:date>
    </item>
    <item>
      <title>Re: Get a value from a table and set it to be a numeric number for later reference.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Get-a-value-from-a-table-and-set-it-to-be-a-numeric-number-for/m-p/765929#M30592</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp; for your help and questions!&lt;/P&gt;&lt;P&gt;Yes,&amp;nbsp;&lt;SPAN&gt;by table I mean a SAS dataset.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;- The information in the table is as below&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="phongpham_0-1630700181944.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/63283i869835558A85DDAE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="phongpham_0-1630700181944.png" alt="phongpham_0-1630700181944.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;- By the numeric number here, I mean number 9 in the N_miss columns.&lt;/P&gt;&lt;P&gt;- I want to put that number of N_miss (9) into line 3 like this " do offset = 1 to N_miss". Since this months, N_miss is 9, I am temporarily put it =9, but next month, the number can change, so I would like to automate it.&lt;/P&gt;&lt;P&gt;-&amp;nbsp; I not quite understand what do you want to say in your example. Do you mean merging dataset, but here I want to get number from dataset and set this number as a reference to stop a loop.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="sas"&gt;data exploded;
  set delta;
  do offset = 1 to 9;
     New_n_quarter = offset + n_quarter;
     New_gdp_base1 = gdp_base1 + delta_GDP * offset ;
     New_RTO_base1 = RTO_base1 + delta_RTO * offset ;
     New_ICR_base1 = ICR_base1 + delta_ICR * offset ;
     New_BCG_base1 = BCG_base1 + delta_BCG * offset ;
     output;
  end;
run;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Sep 2021 20:30:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Get-a-value-from-a-table-and-set-it-to-be-a-numeric-number-for/m-p/765929#M30592</guid>
      <dc:creator>phongpham</dc:creator>
      <dc:date>2021-09-03T20:30:47Z</dc:date>
    </item>
    <item>
      <title>Re: Get a value from a table and set it to be a numeric number for later reference.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Get-a-value-from-a-table-and-set-it-to-be-a-numeric-number-for/m-p/765939#M30597</link>
      <description>&lt;P&gt;If you have a variable name N_MISS that is already in the dataset then why make things complicated?&lt;/P&gt;
&lt;P&gt;Just reference the variable N_MISS in the DO loop.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set delta;
  do offset=1 to n_miss;
     ....
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 Sep 2021 21:23:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Get-a-value-from-a-table-and-set-it-to-be-a-numeric-number-for/m-p/765939#M30597</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-09-03T21:23:51Z</dc:date>
    </item>
    <item>
      <title>Re: Get a value from a table and set it to be a numeric number for later reference.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Get-a-value-from-a-table-and-set-it-to-be-a-numeric-number-for/m-p/765951#M30600</link>
      <description>Thanks Tom. Very much appreciate your help! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Fri, 03 Sep 2021 21:58:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Get-a-value-from-a-table-and-set-it-to-be-a-numeric-number-for/m-p/765951#M30600</guid>
      <dc:creator>phongpham</dc:creator>
      <dc:date>2021-09-03T21:58:22Z</dc:date>
    </item>
  </channel>
</rss>

