<?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: SAS macro loop not considering one macro variable in conditional logic statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-loop-not-considering-one-macro-variable-in-conditional/m-p/897185#M354533</link>
    <description>&lt;P&gt;I forgot to copy that over from my program. Whoops, it's:&lt;BR /&gt;%let cntlist = &amp;amp;sqlobs;&lt;BR /&gt;&lt;BR /&gt;placed after proc sql and before the macro.&lt;/P&gt;</description>
    <pubDate>Wed, 04 Oct 2023 17:10:11 GMT</pubDate>
    <dc:creator>lsandell</dc:creator>
    <dc:date>2023-10-04T17:10:11Z</dc:date>
    <item>
      <title>SAS macro loop not considering one macro variable in conditional logic statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-loop-not-considering-one-macro-variable-in-conditional/m-p/897180#M354531</link>
      <description>&lt;P&gt;Hi there, I am writing a macro loop to run univariate tests and output test 3 results to datasets. This loop is intended for a large dataset where I have too many variables to include in individual macro calls. I want to run 2 different modeling frameworks based on the format applied to numeric variables. Right now, the format (i.e., &amp;amp;fmtlist) is not being considered and my 0/1 variables that have the Y. format (0="no", 1="yes") applied are not being run within the logistic regression PROC. Any ideas for why this is being ignored?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I do not get any error messages, but my results are incorrect as all my "numeric" variables are being fed into the PROC GLM, despite having my Y. format applied.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Additionally, I would like to append all the results together into one dataset. I need to figure that out, once I get the correct results to be output.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format library = form.formats;&lt;BR /&gt;value y&lt;BR /&gt;.= 'Missing'&lt;BR /&gt;0= 'No'&lt;BR /&gt;1= 'Yes'&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc contents data = x varnum out=variable_list; run;&lt;BR /&gt;
data variable_list;
length format $1.;
set variable_list;
run;

proc sql noprint select name,type,format
into :varlist separated by ' ',
:typelist separated by ' ',
:fmtlist separated by ' '
from variable_list; 
quit;
%let cntlist = &amp;amp;sqlobs;&lt;BR /&gt;
%macro univar;
%do i=1 %to %cntlist;

%if %scan(&amp;amp;typelist, &amp;amp;i)=1 %then %do;

%if %scan(&amp;amp;fmtlist, &amp;amp;i)="Y" %then %do;
proc logistic data = &amp;amp;data;
	format %scan(&amp;amp;varlist, &amp;amp;i) y.;
	class %scan(&amp;amp;varlist, &amp;amp;i) (ref=FIRST) / param = ref;
	model outcome(event="Y") =  %scan(&amp;amp;varlist, &amp;amp;i);
	ods output modelANOVA = nfit&amp;amp;i;
	run;
	%end;

%else %if %scan(&amp;amp;fmtlist, &amp;amp;i) ne "Y" %then %do;
proc glm data = &amp;amp;data;
	class outcome (ref="N") / param = ref;
	model %scan(&amp;amp;varlist, &amp;amp;i) = exposure;
	ods output modelANOVA = cfit&amp;amp;i;
	quit;
	%end;
%end;

%else %if %scan(&amp;amp;typelist, &amp;amp;i)=2 %then %do;
proc logistic data = &amp;amp;data;
	class %scan(&amp;amp;varlist, &amp;amp;i) (ref=FIRST) / param = ref;
	model outcome(event="Y") =  %scan(&amp;amp;varlist, &amp;amp;i);
	ods output modelANOVA = cfit&amp;amp;i;
	run;
	%end;

%end;
%mend univar;
%univar;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;first values from the log&lt;/STRONG&gt;: %put &amp;amp;fmtlist; $ $ Y $ $ Y Y&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Oct 2023 17:26:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-loop-not-considering-one-macro-variable-in-conditional/m-p/897180#M354531</guid>
      <dc:creator>lsandell</dc:creator>
      <dc:date>2023-10-04T17:26:07Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro loop not considering one macro variable in conditional logic statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-loop-not-considering-one-macro-variable-in-conditional/m-p/897183#M354532</link>
      <description>&lt;P&gt;Where is the definition of macro cntlist?&lt;/P&gt;</description>
      <pubDate>Wed, 04 Oct 2023 17:05:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-loop-not-considering-one-macro-variable-in-conditional/m-p/897183#M354532</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-10-04T17:05:48Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro loop not considering one macro variable in conditional logic statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-loop-not-considering-one-macro-variable-in-conditional/m-p/897185#M354533</link>
      <description>&lt;P&gt;I forgot to copy that over from my program. Whoops, it's:&lt;BR /&gt;%let cntlist = &amp;amp;sqlobs;&lt;BR /&gt;&lt;BR /&gt;placed after proc sql and before the macro.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Oct 2023 17:10:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-loop-not-considering-one-macro-variable-in-conditional/m-p/897185#M354533</guid>
      <dc:creator>lsandell</dc:creator>
      <dc:date>2023-10-04T17:10:11Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro loop not considering one macro variable in conditional logic statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-loop-not-considering-one-macro-variable-in-conditional/m-p/897186#M354534</link>
      <description>&lt;P&gt;This is a situation where LOOKING AT the data, in this case SAS data set VARIABLE_LIST would likely solve your program as you can see what values are in the variable named FORMAT, and it is these values which become part of macro variable &amp;amp;FMTLIST.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alternatively, you could simply have the macro processor display in the log the values of macro variable &amp;amp;FMTLIST.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put &amp;amp;=fmtlist;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, LOOK AT this macro variable or the original data. What do you see? Can you show it to us?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This line&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;%if %scan(&amp;amp;fmtlist, &amp;amp;i)="Y" %then %do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;probably will never work, unless the i-th element of &amp;amp;fmtlist is "Y", including the quotes, and Y must be capitalized. Is any element of &amp;amp;fmlist "Y"? I don't think so, you are deriving &amp;amp;fmtlist from format names a provided by PROC CONTENTS, and none of the formats are going to be "Y".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This line&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;%else %if %scan(&amp;amp;fmtlist, &amp;amp;i) ne "Y" %then %do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;will likely&amp;nbsp;&lt;FONT color="#FF0000"&gt;always&lt;/FONT&gt; cause the PROC GLM to execute as there are likely no values of the macro variable &amp;amp;fmtlist that are equal to "Y" (including the double quotes and with capital Y).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What will work? I don't know, you haven't shown us the values in &amp;amp;fmtlist&lt;/P&gt;</description>
      <pubDate>Wed, 04 Oct 2023 17:12:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-loop-not-considering-one-macro-variable-in-conditional/m-p/897186#M354534</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-10-04T17:12:30Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro loop not considering one macro variable in conditional logic statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-loop-not-considering-one-macro-variable-in-conditional/m-p/897187#M354535</link>
      <description>&lt;P&gt;Not every data set will actually have a FORMAT reported by Proc Contents.&lt;/P&gt;
&lt;P&gt;Run this an look at the values in the FORMAT variable of the output data set:&lt;/P&gt;
&lt;PRE&gt;proc contents data =sashelp.class varnum out=variable_list; run;
&lt;/PRE&gt;
&lt;P&gt;That is an indication of default formats for each variable type. So for what appears to be your purpose before adding a value to the "list" you have to make sure there is one, and likely check if the variable type is numeric and use BEST and CHAR if character (or B and C).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the purpose of extracting the first letter of a format to begin with? Sounds pretty hokey for any usage.&lt;/P&gt;
&lt;P&gt;Base64&lt;/P&gt;
&lt;P&gt;Binary ( and you need a type to tell if you want the Character or Numeric version)&lt;/P&gt;
&lt;P&gt;B8601 (about two dozen flavors)&lt;/P&gt;
&lt;P&gt;Best&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Oct 2023 17:17:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-loop-not-considering-one-macro-variable-in-conditional/m-p/897187#M354535</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-10-04T17:17:58Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro loop not considering one macro variable in conditional logic statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-loop-not-considering-one-macro-variable-in-conditional/m-p/897188#M354536</link>
      <description>I do see Y in the &amp;amp;fmtlist output in the log. I placed in quotes as it is character. &lt;BR /&gt;&lt;BR /&gt;I can't edit my original post to include the log contents, so here is an excerpt of the first values from the log:  %put &amp;amp;fmtlist; $  $      Y       $  $   Y   Y   .</description>
      <pubDate>Wed, 04 Oct 2023 17:18:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-loop-not-considering-one-macro-variable-in-conditional/m-p/897188#M354536</guid>
      <dc:creator>lsandell</dc:creator>
      <dc:date>2023-10-04T17:18:06Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro loop not considering one macro variable in conditional logic statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-loop-not-considering-one-macro-variable-in-conditional/m-p/897193#M354537</link>
      <description>&lt;P&gt;Y is not "Y"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro dothis;
%let var=Y;
%if &amp;amp;var="Y" %then %put Value is Equal;
%mend;
%dothis
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;No quotes required here, macro processing treats all text as text, even if they look like numbers. The %if in your code is testing to see if the macro variable is equal to the three characters "Y" (double quote-Y-double quote)&lt;/P&gt;</description>
      <pubDate>Wed, 04 Oct 2023 17:28:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-loop-not-considering-one-macro-variable-in-conditional/m-p/897193#M354537</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-10-04T17:28:04Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro loop not considering one macro variable in conditional logic statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-loop-not-considering-one-macro-variable-in-conditional/m-p/897195#M354538</link>
      <description>Ah, that makes sense. Thank you for clarifying the macro processing details.</description>
      <pubDate>Wed, 04 Oct 2023 17:27:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-loop-not-considering-one-macro-variable-in-conditional/m-p/897195#M354538</guid>
      <dc:creator>lsandell</dc:creator>
      <dc:date>2023-10-04T17:27:34Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro loop not considering one macro variable in conditional logic statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-loop-not-considering-one-macro-variable-in-conditional/m-p/897196#M354539</link>
      <description>Did you run the macro with symbolgen and mprint options on? If so, what does the log show for those steps where it errors out?</description>
      <pubDate>Wed, 04 Oct 2023 17:28:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-loop-not-considering-one-macro-variable-in-conditional/m-p/897196#M354539</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-10-04T17:28:30Z</dc:date>
    </item>
  </channel>
</rss>

