<?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: Calling numeric variable from a list in a loop in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/Calling-numeric-variable-from-a-list-in-a-loop/m-p/480502#M24990</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/183607"&gt;@fafrin420&lt;/a&gt;&amp;nbsp;I am unable to copy paste the pic data, can you paste that as plain text plz?&lt;/P&gt;</description>
    <pubDate>Mon, 23 Jul 2018 15:54:14 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-07-23T15:54:14Z</dc:date>
    <item>
      <title>Calling numeric variable from a list in a loop</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Calling-numeric-variable-from-a-list-in-a-loop/m-p/480306#M24976</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data A;
input x @@;
datalines;
0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
;


proc sql noprint;                              
 select x into :List separated by ' '
 from A;
quit;
%put List = &amp;amp;List; 

%let N2 = %sysfunc(countw(&amp;amp;List));

%macro ratio; 	
data DataSET; set DataSET;	
%do i=1 %to &amp;amp;N2;
%let var = %scan(&amp;amp;List, &amp;amp;i);
 Total = Value + &amp;amp;List;

%end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to store numeric variables in a list. And then call each variable from that list (in a loop) and use that variable to do some operations. The above program is not being able to read the variables from the list as numeric. Can you suggest a better way to do it?&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My error log says "Expecting an arithmatic operator"&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jul 2018 00:14:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Calling-numeric-variable-from-a-list-in-a-loop/m-p/480306#M24976</guid>
      <dc:creator>fafrin420</dc:creator>
      <dc:date>2018-07-23T00:14:12Z</dc:date>
    </item>
    <item>
      <title>Re: Calling numeric variable from a list in a loop</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Calling-numeric-variable-from-a-list-in-a-loop/m-p/480311#M24979</link>
      <description>&lt;P&gt;There are several things wrong in your code and it is not clear what you are trying to accomplish.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First of all, you are not storing any variables in any list. In your SQL Procedure, you simply save the ten numbers defined in the previous data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Next, you do this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let N2 = %sysfunc(countw(&amp;amp;List));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and I assume you want N2 to equal 10 since you have ten numbers in the macro variable List. However this code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put N2=&amp;amp;N2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;reveals that N2=19.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Finally, you try to define some macro, but you have no %MEND Statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Be more specific about what you are trying to accomplish.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jul 2018 00:25:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Calling-numeric-variable-from-a-list-in-a-loop/m-p/480311#M24979</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-07-23T00:25:02Z</dc:date>
    </item>
    <item>
      <title>Re: Calling numeric variable from a list in a loop</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Calling-numeric-variable-from-a-list-in-a-loop/m-p/480321#M24981</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data A;
input x @@;
datalines;
0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
;


proc sql noprint;                              
 select x into :List separated by ' '
 from A;
quit;
%put List = &amp;amp;List; 

%let N2 = %sysfunc(countw(&amp;amp;List));

%macro ratio; 	
data DataSET; set DataSET;	
%do i=1 %to &amp;amp;N2;
%let var = %scan(&amp;amp;List, &amp;amp;i);
 Total = 10 + &amp;amp;List;

%end;
run;
%mend;

%ratio;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Hi, Sorry I missed the %mend earlier. My goal is to make a loop that would add each variable from the list to the 10 to get me total.&lt;/P&gt;&lt;P&gt;So Total will be 10.1, 10.2, 10.3 etc.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jul 2018 02:16:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Calling-numeric-variable-from-a-list-in-a-loop/m-p/480321#M24981</guid>
      <dc:creator>fafrin420</dc:creator>
      <dc:date>2018-07-23T02:16:09Z</dc:date>
    </item>
    <item>
      <title>Re: Calling numeric variable from a list in a loop</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Calling-numeric-variable-from-a-list-in-a-loop/m-p/480334#M24982</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data A;
input x @@;
datalines;
0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
;

proc sql noprint;                              
 select x into :List separated by ','
 from A;
quit;
%put List = &amp;amp;List; 

%let N2 = %sysfunc(countw(%bquote(&amp;amp;List),%str(,)));
%put &amp;amp;n2;

%macro ratio; 	
	
%do i=1 %to &amp;amp;N2;
%let var = %scan(%bquote(&amp;amp;List), &amp;amp;i,%str(,));
%put  var=&amp;amp;var;
%let Total = %sysevalf(10 + &amp;amp;var);
%put total =&amp;amp;total ;
%end;
%mend;
%ratio&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 Jul 2018 02:49:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Calling-numeric-variable-from-a-list-in-a-loop/m-p/480334#M24982</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-07-23T02:49:05Z</dc:date>
    </item>
    <item>
      <title>Re: Calling numeric variable from a list in a loop</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Calling-numeric-variable-from-a-list-in-a-loop/m-p/480400#M24985</link>
      <description>&lt;P&gt;Hi Novinosrin,&lt;/P&gt;&lt;P&gt;Thanks a lot for the help. I have one more question. Suppose I want to add the value from the list to&amp;nbsp;another numeric variable "sum"&amp;nbsp;from the dataset B with an "if" Statement. Suppose,&lt;/P&gt;&lt;P&gt;If something=1 then Total = Sum + Value from the list. Can you please let me know a way to do so?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data A;
input x @@;
datalines;
0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
;

proc sql noprint;                              
 select x into :List separated by ','
 from A;
quit;
%put List = &amp;amp;List; 

%let N2 = %sysfunc(countw(%bquote(&amp;amp;List),%str(,)));
%put &amp;amp;n2;

%macro ratio; 	
Data B; set B;	
%do i=1 %to &amp;amp;N2;
%let var = %scan(%bquote(&amp;amp;List), &amp;amp;i,%str(,));
%put  var=&amp;amp;var;
%let if Something =1 then Total = %sysevalf(10 + &amp;amp;var);
%put total =&amp;amp;total ;
%end;
%mend;
%ratio&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jul 2018 12:33:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Calling-numeric-variable-from-a-list-in-a-loop/m-p/480400#M24985</guid>
      <dc:creator>fafrin420</dc:creator>
      <dc:date>2018-07-23T12:33:09Z</dc:date>
    </item>
    <item>
      <title>Re: Calling numeric variable from a list in a loop</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Calling-numeric-variable-from-a-list-in-a-loop/m-p/480438#M24987</link>
      <description>&lt;P&gt;Good morning&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/183607"&gt;@fafrin420&lt;/a&gt;&amp;nbsp; Your requirement sounds like can be comfortably and easily accomplished without the need of macro to generate a sas code.&amp;nbsp; Please provide a comprehensive and nice representative&amp;nbsp; sample of your datasets and your output dataset(your expected) with a line saying what you want to accomplish.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Once you give us that full info, and if you still insist on macros, of course we shall compare and do both.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jul 2018 13:56:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Calling-numeric-variable-from-a-list-in-a-loop/m-p/480438#M24987</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-07-23T13:56:18Z</dc:date>
    </item>
    <item>
      <title>Re: Calling numeric variable from a list in a loop</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Calling-numeric-variable-from-a-list-in-a-loop/m-p/480494#M24989</link>
      <description>&lt;P&gt;Good morning &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;. Here are my input and output datasets. My goal is to find total1, total2, total3, total4, total5, total6 by adding sum to each value .1,.2,.3,.4,.5,.6 given that something=1.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Dataset input.JPG" style="width: 265px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/21938i7EF0E0B508AA17DE/image-size/large?v=v2&amp;amp;px=999" role="button" title="Dataset input.JPG" alt="Dataset input.JPG" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Dataset output.JPG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/21940i30E0D39CD96D180C/image-size/large?v=v2&amp;amp;px=999" role="button" title="Dataset output.JPG" alt="Dataset output.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jul 2018 15:42:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Calling-numeric-variable-from-a-list-in-a-loop/m-p/480494#M24989</guid>
      <dc:creator>fafrin420</dc:creator>
      <dc:date>2018-07-23T15:42:16Z</dc:date>
    </item>
    <item>
      <title>Re: Calling numeric variable from a list in a loop</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Calling-numeric-variable-from-a-list-in-a-loop/m-p/480502#M24990</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/183607"&gt;@fafrin420&lt;/a&gt;&amp;nbsp;I am unable to copy paste the pic data, can you paste that as plain text plz?&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jul 2018 15:54:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Calling-numeric-variable-from-a-list-in-a-loop/m-p/480502#M24990</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-07-23T15:54:14Z</dc:date>
    </item>
    <item>
      <title>Re: Calling numeric variable from a list in a loop</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Calling-numeric-variable-from-a-list-in-a-loop/m-p/480527#M24996</link>
      <description>&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Something&lt;/TD&gt;&lt;TD&gt;Sum&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;13&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;14&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;13&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;13&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;14&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;13&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Hi, Here is the input data set.&lt;/P&gt;&lt;P&gt;For the values to be added to sum you have:&amp;nbsp;&lt;/P&gt;&lt;P&gt;0.1, 0.2, 0.3, 0.4, 0.5, 0.6&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jul 2018 16:38:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Calling-numeric-variable-from-a-list-in-a-loop/m-p/480527#M24996</guid>
      <dc:creator>fafrin420</dc:creator>
      <dc:date>2018-07-23T16:38:29Z</dc:date>
    </item>
    <item>
      <title>Re: Calling numeric variable from a list in a loop</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Calling-numeric-variable-from-a-list-in-a-loop/m-p/480536#M24997</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*input dataset 1*/
data have;
input something sum;
cards;
1 12
2 13
1 14
3 13
1 12
5 13
1 14
2 13
;
/*input dataset 2*/
data A;
input x @@;
datalines;
0.1 0.2 0.3 0.4 0.5 0.6
;

proc sql;
select count(*) into :n
from a;
quit;

proc transpose data=a out=_a prefix=a;
var x;
run;

data want;
set have;
array total(&amp;amp;n);
if _n_=1 then set _a;
array t(*) a:;
do _n_=1 to dim(t);
if something=1 then total(_n_)=t(_n_)+sum;
else total(_n_)=sum;
end;
keep something sum total:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 Jul 2018 17:14:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Calling-numeric-variable-from-a-list-in-a-loop/m-p/480536#M24997</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-07-23T17:14:26Z</dc:date>
    </item>
  </channel>
</rss>

