<?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 How to use a set of values from a macro variable(s) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-set-of-values-from-a-macro-variable-s/m-p/785798#M250825</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I'm trying to write an iteration program and the main idea is that I want my program run multiple time and each time to use one value from a macro variable with a set of values.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The example code is as below:&lt;/P&gt;&lt;P&gt;data critlist;&lt;BR /&gt;input var1 var2;&lt;BR /&gt;datalines;&lt;BR /&gt;1.12 1.19&lt;BR /&gt;1.12 1.29&lt;BR /&gt;1.12 1.36&lt;BR /&gt;1.12 1.41&lt;BR /&gt;1.22 1.19&lt;BR /&gt;1.22 1.29&lt;BR /&gt;1.22 1.36&lt;BR /&gt;1.22 1.41&lt;BR /&gt;1.32 1.19&lt;BR /&gt;1.32 1.29&lt;BR /&gt;1.32 1.36&lt;BR /&gt;1.32 1.41&lt;BR /&gt;1.42 1.19&lt;BR /&gt;1.42 1.29&lt;BR /&gt;1.42 1.36&lt;BR /&gt;1.42 1.41&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;select var1, var2 into :mvar1 separated by ' ', mvar2 separated by ' '&lt;BR /&gt;from critlist;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So my question is i don't know how to write my data step so that i can put the value from the macro variable into use:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data output; set input;&lt;/P&gt;&lt;P&gt;if ana_var &amp;gt;&amp;nbsp;&lt;U&gt;&lt;EM&gt;1.12&lt;/EM&gt;&lt;/U&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; *Here i don't know what to so that SAS will know if the the 1st value from &amp;amp;mvar1;&lt;/P&gt;&lt;P&gt;then ana_crit = "using &lt;U&gt;&lt;EM&gt;1.12&lt;/EM&gt;&lt;/U&gt;";&amp;nbsp; &amp;nbsp; &amp;nbsp; *Here i don't know what to so that SAS will know if the the 1st value from &amp;amp;mvar1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if ana_var &amp;gt; &lt;U&gt;&lt;EM&gt;1.19&lt;/EM&gt;&lt;/U&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; *Here i don't know what to so that SAS will know if the the 1st value from &amp;amp;mvar2;&lt;/P&gt;&lt;P&gt;then ana_crit = "using &lt;U&gt;&lt;EM&gt;1.19&lt;/EM&gt;&lt;/U&gt;";&amp;nbsp; &amp;nbsp; &amp;nbsp; *Here i don't know what to so that SAS will know if the the 1st value from &amp;amp;mvar2;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;then run this data step multiple times to use ALL values from &amp;amp;mvar1 and &amp;amp;mvar2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;so basically, i want to run my data step multiple times using each of the values i assigned to &amp;amp;mvar1 and &amp;amp;mvar2. But i don't know how to write the step....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;Tina&lt;/P&gt;</description>
    <pubDate>Mon, 13 Dec 2021 17:01:20 GMT</pubDate>
    <dc:creator>yahoo0806</dc:creator>
    <dc:date>2021-12-13T17:01:20Z</dc:date>
    <item>
      <title>How to use a set of values from a macro variable(s)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-set-of-values-from-a-macro-variable-s/m-p/785798#M250825</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I'm trying to write an iteration program and the main idea is that I want my program run multiple time and each time to use one value from a macro variable with a set of values.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The example code is as below:&lt;/P&gt;&lt;P&gt;data critlist;&lt;BR /&gt;input var1 var2;&lt;BR /&gt;datalines;&lt;BR /&gt;1.12 1.19&lt;BR /&gt;1.12 1.29&lt;BR /&gt;1.12 1.36&lt;BR /&gt;1.12 1.41&lt;BR /&gt;1.22 1.19&lt;BR /&gt;1.22 1.29&lt;BR /&gt;1.22 1.36&lt;BR /&gt;1.22 1.41&lt;BR /&gt;1.32 1.19&lt;BR /&gt;1.32 1.29&lt;BR /&gt;1.32 1.36&lt;BR /&gt;1.32 1.41&lt;BR /&gt;1.42 1.19&lt;BR /&gt;1.42 1.29&lt;BR /&gt;1.42 1.36&lt;BR /&gt;1.42 1.41&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;select var1, var2 into :mvar1 separated by ' ', mvar2 separated by ' '&lt;BR /&gt;from critlist;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So my question is i don't know how to write my data step so that i can put the value from the macro variable into use:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data output; set input;&lt;/P&gt;&lt;P&gt;if ana_var &amp;gt;&amp;nbsp;&lt;U&gt;&lt;EM&gt;1.12&lt;/EM&gt;&lt;/U&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; *Here i don't know what to so that SAS will know if the the 1st value from &amp;amp;mvar1;&lt;/P&gt;&lt;P&gt;then ana_crit = "using &lt;U&gt;&lt;EM&gt;1.12&lt;/EM&gt;&lt;/U&gt;";&amp;nbsp; &amp;nbsp; &amp;nbsp; *Here i don't know what to so that SAS will know if the the 1st value from &amp;amp;mvar1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if ana_var &amp;gt; &lt;U&gt;&lt;EM&gt;1.19&lt;/EM&gt;&lt;/U&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; *Here i don't know what to so that SAS will know if the the 1st value from &amp;amp;mvar2;&lt;/P&gt;&lt;P&gt;then ana_crit = "using &lt;U&gt;&lt;EM&gt;1.19&lt;/EM&gt;&lt;/U&gt;";&amp;nbsp; &amp;nbsp; &amp;nbsp; *Here i don't know what to so that SAS will know if the the 1st value from &amp;amp;mvar2;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;then run this data step multiple times to use ALL values from &amp;amp;mvar1 and &amp;amp;mvar2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;so basically, i want to run my data step multiple times using each of the values i assigned to &amp;amp;mvar1 and &amp;amp;mvar2. But i don't know how to write the step....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;Tina&lt;/P&gt;</description>
      <pubDate>Mon, 13 Dec 2021 17:01:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-set-of-values-from-a-macro-variable-s/m-p/785798#M250825</guid>
      <dc:creator>yahoo0806</dc:creator>
      <dc:date>2021-12-13T17:01:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to use a set of values from a macro variable(s)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-set-of-values-from-a-macro-variable-s/m-p/785821#M250836</link>
      <description>&lt;P&gt;Hi Tina&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/223143"&gt;@yahoo0806&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I cannot figure out what you are trying to achieve, so I might be totally wrong in my solution, but the code works as a demonstration of how one can loop over the mvar lists, take the next values and use them in a data step.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I can be of any further help, please write back.&lt;/P&gt;
&lt;P&gt;Erik&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*The example code is as below:;

data critlist;
input var1 var2;
datalines;
1.12 1.19
1.12 1.29
1.12 1.36
1.12 1.41
1.22 1.19
1.22 1.29
1.22 1.36
1.22 1.41
1.32 1.19
1.32 1.29
1.32 1.36
1.32 1.41
1.42 1.19
1.42 1.29
1.42 1.36
1.42 1.41
;

data input (drop=i); /* For this example the input ds must end with a 0 (zero); */
	do i = 101 to 280 by 11;
		ana_var = i / 100;
		output;
	end;
run;

proc sql noprint;
select var1, var2 into :mvar1 separated by ' ', : mvar2 separated by ' '
from critlist;
quit;
%let loopcount = &amp;amp;sqlobs;

%let input = input; /* input dsname into macro variable */
%let outputprefix = out; /* prefix for numbered output ds */
%macro m;
	%do i = 1 %to &amp;amp;loopcount;
		%let thislow = %scan(&amp;amp;mvar1,&amp;amp;i,%str( ));
		%let thisuse = %scan(&amp;amp;mvar2,&amp;amp;i,%str( ));
		%put &amp;amp;=thislow &amp;amp;=thisuse;

		%if &amp;amp;i = 1 %then %let thisinput = &amp;amp;input;
		%else %let thisinput = &amp;amp;outputprefix%eval(&amp;amp;i-1);
		%put &amp;amp;=thisinput;

		data &amp;amp;outputprefix&amp;amp;i; set &amp;amp;thisinput;
			if ana_var &amp;gt; &amp;amp;thislow then ana_crit = catx(' ',"using","&amp;amp;thisuse");
		run;
	%end;
%mend;
%m;
 

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Dec 2021 17:53:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-set-of-values-from-a-macro-variable-s/m-p/785821#M250836</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2021-12-13T17:53:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to use a set of values from a macro variable(s)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-set-of-values-from-a-macro-variable-s/m-p/785824#M250837</link>
      <description>&lt;P&gt;Yes, please explain what you are trying to do here. I don't think you need macros at all, but then again, I don't understand the goal here.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Dec 2021 18:07:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-set-of-values-from-a-macro-variable-s/m-p/785824#M250837</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-12-13T18:07:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to use a set of values from a macro variable(s)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-set-of-values-from-a-macro-variable-s/m-p/785847#M250848</link>
      <description>&lt;P&gt;If you have a list of value in a macro variable use %SCAN() to extract one of them.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let i=1 ;
%put &amp;amp;=i %scan(&amp;amp;mvar1,&amp;amp;i,%str( ));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But why not just use your actual values instead of converting them from numbers into text and back again?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data output; 
  if _n_=1 then set crit (firstobs=&amp;amp;i obs=&amp;amp;i keep=var1 var2);
  set input;
  if ana_var &amp;gt; var1 then ana_crit = catx(' ','using',var1); 
  if ana_var &amp;gt; var2 then ana_crit = catx(' ','using',var2); 
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Dec 2021 18:44:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-set-of-values-from-a-macro-variable-s/m-p/785847#M250848</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-12-13T18:44:01Z</dc:date>
    </item>
  </channel>
</rss>

