<?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: Feeding individual char values into procedure in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Feeding-individual-char-values-into-procedure/m-p/464458#M118421</link>
    <description>&lt;P&gt;a quick pointers here with which i am sure you can modify&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods graphics on;
%macro h;
%local valuelist;
%let valuelist = IM PD;
title "&amp;amp;valuelist Data";
%do i=1 to %sysfunc(countw(&amp;amp;valuelist));
%let var=%scan(&amp;amp;valuelist,&amp;amp;i);
proc quantreg data=res_costs ci=sparsity/iid algorithm=interior(tolerance=1.e-4);
	where program = "&amp;amp;var"
					;
	model charges =  /
	quantile = 0.25 to 0.75 by 0.25
	plot=quantplot;
run;
%end;
%mend h;
%h
ods graphics off;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 23 May 2018 17:09:32 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-05-23T17:09:32Z</dc:date>
    <item>
      <title>Feeding individual char values into procedure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Feeding-individual-char-values-into-procedure/m-p/464450#M118417</link>
      <description>&lt;P&gt;Well a pretty basic question for savvy data step folks. I have a finite set of character values&amp;nbsp;in a variable and I want to run&amp;nbsp;a procedure over and over cycling through the character list. So it will input the value into&amp;nbsp;TITLE&amp;nbsp;statement&amp;nbsp;and&amp;nbsp;WHERE statement.&amp;nbsp;A generic version of my attempt is below. Ideally this code would run quantreg twice, once for variable = 'IM' and once for 'PD'&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods graphics on;
%let valuelist = 'IM' 'PD';
title "&amp;amp;valuelist Data";
proc quantreg data=res_costs ci=sparsity/iid algorithm=interior(tolerance=1.e-4);
	where program = &amp;amp;valuelist    
					;
	model charges =  /
	quantile = 0.25 to 0.75 by 0.25
	plot=quantplot;
run;
%put &amp;amp;valuelist;
ods graphics off;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 May 2018 16:43:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Feeding-individual-char-values-into-procedure/m-p/464450#M118417</guid>
      <dc:creator>H</dc:creator>
      <dc:date>2018-05-23T16:43:49Z</dc:date>
    </item>
    <item>
      <title>Re: Feeding individual char values into procedure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Feeding-individual-char-values-into-procedure/m-p/464458#M118421</link>
      <description>&lt;P&gt;a quick pointers here with which i am sure you can modify&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods graphics on;
%macro h;
%local valuelist;
%let valuelist = IM PD;
title "&amp;amp;valuelist Data";
%do i=1 to %sysfunc(countw(&amp;amp;valuelist));
%let var=%scan(&amp;amp;valuelist,&amp;amp;i);
proc quantreg data=res_costs ci=sparsity/iid algorithm=interior(tolerance=1.e-4);
	where program = "&amp;amp;var"
					;
	model charges =  /
	quantile = 0.25 to 0.75 by 0.25
	plot=quantplot;
run;
%end;
%mend h;
%h
ods graphics off;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 May 2018 17:09:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Feeding-individual-char-values-into-procedure/m-p/464458#M118421</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-05-23T17:09:32Z</dc:date>
    </item>
    <item>
      <title>Re: Feeding individual char values into procedure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Feeding-individual-char-values-into-procedure/m-p/464486#M118429</link>
      <description>&lt;P&gt;First of all, thanks for the reply. The code doesn't quite work (run).&amp;nbsp; Probably my fault for not having an executable example. It first wanted a "%" on the 'to', then gave the following error message:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
NOTE: No observations were selected from data set
      WORK.RES_COSTS.
NOTE: The SAS System stopped processing this step because of
      errors.
NOTE: PROCEDURE QUANTREG used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds





NOTE: No observations were selected from data set
      WORK.RES_COSTS.
NOTE: The SAS System stopped processing this step because of
      errors.
NOTE: PROCEDURE QUANTREG used (Total process time):
      real time           0.00 seconds
      cpu time            0.03 seconds
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;While staring at it I cannot think how to resolve the undefined issue. Perhaps, we can use the Sashelp.Heart set to get on common ground. An equivalent would be:&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=" language-sas"&gt;ods graphics on;
proc quantreg data=sashelp.heart ci=sparsity/iid algorithm=interior(tolerance=1.e-4);
	where Sex = "Female"
			/*		"Male"	*/
						;
	model weight =  /
	quantile = 0.25 to 0.75 by 0.25
	plot=quantplot;
run;
ods graphics off;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 May 2018 17:48:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Feeding-individual-char-values-into-procedure/m-p/464486#M118429</guid>
      <dc:creator>H</dc:creator>
      <dc:date>2018-05-23T17:48:42Z</dc:date>
    </item>
    <item>
      <title>Re: Feeding individual char values into procedure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Feeding-individual-char-values-into-procedure/m-p/464489#M118431</link>
      <description>&lt;P&gt;to to %to was a syntax error on my part. Sorry about that&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you follow the logic with&amp;nbsp; &lt;EM&gt;&lt;STRONG&gt;options mlogic symbolgen mprint;&amp;nbsp;&lt;/STRONG&gt; &lt;/EM&gt;before the macro beginning that explains the processing of the program in the log&lt;/P&gt;</description>
      <pubDate>Wed, 23 May 2018 17:53:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Feeding-individual-char-values-into-procedure/m-p/464489#M118431</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-05-23T17:53:06Z</dc:date>
    </item>
    <item>
      <title>Re: Feeding individual char values into procedure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Feeding-individual-char-values-into-procedure/m-p/464496#M118437</link>
      <description>&lt;P&gt;Your basic problem is attempting to use WHERE= with multiple values.&lt;/P&gt;
&lt;P&gt;As you have found a statement like&lt;/P&gt;
&lt;P&gt;Where program = 'A' 'B' ;&lt;/P&gt;
&lt;P&gt;is a syntax error. The appropriate would be&lt;/P&gt;
&lt;P&gt;Where program in ('A' 'B');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you always have more than one value in your value list you could use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Where program in (&amp;amp;valuelist);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if you are going to mix single and double then you need to implement some logic to use either "Where =" or "where in".&lt;/P&gt;
&lt;P&gt;Perhaps something like:&lt;/P&gt;
&lt;PRE&gt;%macro wherelist (parm);
   %if %sysfunc(countw(&amp;amp;parm.)) &amp;gt; 1 %then %do;
      where program in (&amp;amp;parm.);
   %end;
   %else %do;
      where program = &amp;amp;parm.;
   %end;
%mend;
%let valuelist = 'IM' 'PD';

title "&amp;amp;valuelist Data";
proc quantreg data=res_costs ci=sparsity/iid algorithm=interior(tolerance=1.e-4);
	%wherelist ( &amp;amp;valuelist.);
					;
	model charges =  /
	quantile = 0.25 to 0.75 by 0.25
	plot=quantplot;
run;
&lt;/PRE&gt;
&lt;P&gt;Note that there are potential issues with your "valuelist" being blank or having mismatched quotes that will yield unexpected results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 May 2018 18:08:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Feeding-individual-char-values-into-procedure/m-p/464496#M118437</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-05-23T18:08:52Z</dc:date>
    </item>
    <item>
      <title>Re: Feeding individual char values into procedure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Feeding-individual-char-values-into-procedure/m-p/464502#M118440</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You suggest a need to change from&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;EM&gt;&lt;STRONG&gt;where&amp;nbsp;program in (&amp;amp;parm)&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;to&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;EM&gt;&lt;STRONG&gt;where program = &amp;amp;parm&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;when &amp;amp;parm has a single value instead of a list of values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is that for a performance-based reason?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 May 2018 18:25:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Feeding-individual-char-values-into-procedure/m-p/464502#M118440</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-05-23T18:25:10Z</dc:date>
    </item>
    <item>
      <title>Re: Feeding individual char values into procedure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Feeding-individual-char-values-into-procedure/m-p/464522#M118442</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;- Thx&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The following code worked for me, I have no idea what the option part did, but activated something &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;PRE&gt;&lt;CODE class=" language-sas"&gt;options mlogic symbolgen mprint;
ods graphics on;
%macro h;
%local valuelist;
%let valuelist = IM PD;
%do i=1 %to %sysfunc(countw(&amp;amp;valuelist));
%let var=%scan(&amp;amp;valuelist,&amp;amp;i);
proc quantreg data=res_costs ci=sparsity/iid algorithm=interior(tolerance=1.e-4);
	where program = "&amp;amp;var"
					;
	model charges =  /
	quantile = 0.25 to 0.75 by 0.25
	plot=quantplot;
run;
title "&amp;amp;var";
%end;
%mend h;
%h
ods graphics off;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;- Thx. I was unable to get your suggestion to run. I added the ODS GRAPHICS ON for the full output I was looking for, but it only seemed to run the procedure for IM and not PD. Which theoretically your approach may have been more ideal for me since I would only need to insert the prefix part of code if I wanted to run comparable code later on in my program.&lt;/P&gt;</description>
      <pubDate>Wed, 23 May 2018 18:53:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Feeding-individual-char-values-into-procedure/m-p/464522#M118442</guid>
      <dc:creator>H</dc:creator>
      <dc:date>2018-05-23T18:53:06Z</dc:date>
    </item>
    <item>
      <title>Re: Feeding individual char values into procedure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Feeding-individual-char-values-into-procedure/m-p/464524#M118443</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/2723"&gt;@H&lt;/a&gt;&amp;nbsp;I am glad that %macro h: worked. I will have a pint for you. Have fun and enjoy your day&lt;/P&gt;</description>
      <pubDate>Wed, 23 May 2018 18:53:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Feeding-individual-char-values-into-procedure/m-p/464524#M118443</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-05-23T18:53:07Z</dc:date>
    </item>
    <item>
      <title>Re: Feeding individual char values into procedure</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Feeding-individual-char-values-into-procedure/m-p/464552#M118452</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/2723"&gt;@H&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;- Thx&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;- Thx. I was unable to get your suggestion to run. I added the ODS GRAPHICS ON for the full output I was looking for, but it only seemed to run the procedure for IM and not PD. Which theoretically your approach may have been more ideal for me since I would only need to insert the prefix part of code if I wanted to run comparable code later on in my program.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;From the accepted solution it was because your problem definition was not clear. You did not indicate you wanted, at least to me, that you wanted a single run for each value in the list. I though you wanted to run on records where any of the listed values of Program were present.&lt;/P&gt;</description>
      <pubDate>Wed, 23 May 2018 19:43:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Feeding-individual-char-values-into-procedure/m-p/464552#M118452</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-05-23T19:43:12Z</dc:date>
    </item>
  </channel>
</rss>

