<?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: Why this code is failing? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Why-this-code-is-failing/m-p/263590#M310217</link>
    <description>&lt;P&gt;If you have conditional logic like that, its a case where I would recommend going into macro progrramming.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It sounds like you're trying to generalize a process, so also a good indication that macro programming may be appropriate.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 13 Apr 2016 16:57:21 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-04-13T16:57:21Z</dc:date>
    <item>
      <title>Why this code is failing?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-this-code-is-failing/m-p/263560#M310212</link>
      <description>&lt;P&gt;data x;&lt;BR /&gt;y=1;&lt;BR /&gt;run;&lt;BR /&gt;data x1;&lt;BR /&gt;set x;&lt;BR /&gt;if vtype(y)='C' then do;&lt;BR /&gt;if y=c bg then x=1;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why is it throwing error. Since y is numeric, ideally, it should not go into the loop?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Apr 2016 15:34:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-this-code-is-failing/m-p/263560#M310212</guid>
      <dc:creator>munitech4u</dc:creator>
      <dc:date>2016-04-13T15:34:02Z</dc:date>
    </item>
    <item>
      <title>Re: Why this code is failing?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-this-code-is-failing/m-p/263568#M310213</link>
      <description>&lt;P&gt;Syntax is still checked and this looks like a syntax error. What are you trying to do with "bg" there?&lt;/P&gt;</description>
      <pubDate>Wed, 13 Apr 2016 15:57:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-this-code-is-failing/m-p/263568#M310213</guid>
      <dc:creator>JoshB</dc:creator>
      <dc:date>2016-04-13T15:57:45Z</dc:date>
    </item>
    <item>
      <title>Re: Why this code is failing?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-this-code-is-failing/m-p/263577#M310214</link>
      <description>&lt;P&gt;I run your code and get the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;281  if y=c bg then x=1;
            --
            388
            76
ERROR 388-185: Expecting an arithmetic operator.

ERROR 76-322: Syntax error, statement will be ignored.
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Your x dataset only has the variable y. What are c, bg supposed to be?&lt;/P&gt;</description>
      <pubDate>Wed, 13 Apr 2016 16:22:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-this-code-is-failing/m-p/263577#M310214</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-04-13T16:22:52Z</dc:date>
    </item>
    <item>
      <title>Re: Why this code is failing?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-this-code-is-failing/m-p/263579#M310215</link>
      <description>&lt;P&gt;well. Here is the situation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to impute the values based on the numeric and character in an automated macro. Now if it happens to be numeric values I need to put the condition like "If y=1 then z=0;"&lt;/P&gt;
&lt;P&gt;If y happens to be a character, I want it to be like "If y="A" then z=0;&lt;/P&gt;
&lt;P&gt;Now I have to write these different conditions based on if y is numeric or character. But execute only one, based on whether it is numeric or character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So condition where it is character and goes to the condition under numeric: if y= a bc it fails. while it should have been if y="a bc" under character condition.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Apr 2016 16:29:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-this-code-is-failing/m-p/263579#M310215</guid>
      <dc:creator>munitech4u</dc:creator>
      <dc:date>2016-04-13T16:29:33Z</dc:date>
    </item>
    <item>
      <title>Re: Why this code is failing?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-this-code-is-failing/m-p/263588#M310216</link>
      <description>&lt;P&gt;The simplest fix would be to create a macro variable holding either 1 or "c bg".&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;/P&gt;
&lt;P&gt;set x;&lt;/P&gt;
&lt;P&gt;if vtype(y)='C' then call symput('y_val', '"c bg"');&lt;/P&gt;
&lt;P&gt;else call symput('y_val', '1');&lt;/P&gt;
&lt;P&gt;stop;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then use the macro variable later.&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data x1;&lt;/P&gt;
&lt;P&gt;set x;&lt;/P&gt;
&lt;P&gt;if y = &amp;amp;y_val then x=1;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Apr 2016 16:54:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-this-code-is-failing/m-p/263588#M310216</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-04-13T16:54:31Z</dc:date>
    </item>
    <item>
      <title>Re: Why this code is failing?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-this-code-is-failing/m-p/263590#M310217</link>
      <description>&lt;P&gt;If you have conditional logic like that, its a case where I would recommend going into macro progrramming.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It sounds like you're trying to generalize a process, so also a good indication that macro programming may be appropriate.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Apr 2016 16:57:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-this-code-is-failing/m-p/263590#M310217</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-04-13T16:57:21Z</dc:date>
    </item>
    <item>
      <title>Re: Why this code is failing?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-this-code-is-failing/m-p/263593#M310218</link>
      <description>&lt;P&gt;Ok, here is my full code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;BR /&gt;set &amp;amp;output_lib..&amp;amp;outdata;&lt;BR /&gt;call symput(compress('varn'||_n_),variable_name);&lt;BR /&gt;call symput(compress('bin'||_n_),bins);&lt;BR /&gt;call symput(compress('woe'||_n_),woe);&lt;BR /&gt;call symput(compress('new_var'||_n_),compress(variable_name||"_w"));&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;select count(*)-1 into: max_obs from &amp;amp;output_lib..&amp;amp;outdata ;quit;&lt;/P&gt;
&lt;P&gt;%do i=1 %to &amp;amp;max_obs;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data &amp;amp;output_lib..&amp;amp;out_woe;&lt;BR /&gt;set &amp;amp;dataset;&lt;BR /&gt;if vtype(&amp;amp;&amp;amp;varn&amp;amp;i)='N' then do;&lt;BR /&gt;if &amp;amp;&amp;amp;varn&amp;amp;i=&amp;amp;&amp;amp;bin&amp;amp;i then &amp;amp;&amp;amp;new_var&amp;amp;i=&amp;amp;&amp;amp;woe&amp;amp;i;&lt;BR /&gt;end;&lt;BR /&gt;else do;&lt;BR /&gt;if &amp;amp;&amp;amp;varn&amp;amp;i="&amp;amp;&amp;amp;bin&amp;amp;i" then &amp;amp;&amp;amp;new_var&amp;amp;i=&amp;amp;&amp;amp;woe&amp;amp;i;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;/P&gt;
&lt;P&gt;I will be scanning the variable type while setting the dataset. is there a way around this. else I am planning to get the variable type and merge with&amp;nbsp;&lt;SPAN&gt;&amp;amp;output_lib..&amp;amp;outdata to get the variable type and keep the statements within macro condition and not within datastep.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Apr 2016 17:04:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-this-code-is-failing/m-p/263593#M310218</guid>
      <dc:creator>munitech4u</dc:creator>
      <dc:date>2016-04-13T17:04:47Z</dc:date>
    </item>
    <item>
      <title>Re: Why this code is failing?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-this-code-is-failing/m-p/263605#M310219</link>
      <description>&lt;P&gt;OK, I'll try to modify your code as little as possible.&amp;nbsp; I assume all of this is contained within a macro definition, since %IF would give you an error otherwise.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First, after the %DO statement, add as the first step within the loop:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;data _null_;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;set &amp;amp;dataset;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;if vtype(&amp;amp;&amp;amp;varn&amp;amp;i)='N' then call symputx('bin_val', "&amp;amp;&amp;amp;bin&amp;amp;i");&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;else call symputx('bin_val', "'&amp;amp;&amp;amp;bin&amp;amp;i'");&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;stop;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;run;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then use &amp;amp;BIN_VAL in your DATA step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;data &amp;amp;output_lib..&amp;amp;out_woe;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;set &amp;amp;dataset;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;if &amp;amp;&amp;amp;varn&amp;amp;i=&amp;amp;bin_val then &amp;amp;&amp;amp;new_var&amp;amp;i=&amp;amp;&amp;amp;woe&amp;amp;i;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;run;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All of this assumes that your program is otherwise correct.&amp;nbsp; That part is up to you.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Apr 2016 17:24:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-this-code-is-failing/m-p/263605#M310219</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-04-13T17:24:57Z</dc:date>
    </item>
    <item>
      <title>Re: Why this code is failing?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-this-code-is-failing/m-p/263608#M310220</link>
      <description>Cool. Seems to be working. Thanks!</description>
      <pubDate>Wed, 13 Apr 2016 17:41:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-this-code-is-failing/m-p/263608#M310220</guid>
      <dc:creator>munitech4u</dc:creator>
      <dc:date>2016-04-13T17:41:34Z</dc:date>
    </item>
    <item>
      <title>Re: Why this code is failing?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Why-this-code-is-failing/m-p/263806#M310221</link>
      <description>Is there a way, I can optimize it? Because I here I am setting the dataset for each variable. Can I avoid that and let the code write only the if conditions and then run?</description>
      <pubDate>Thu, 14 Apr 2016 09:57:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Why-this-code-is-failing/m-p/263806#M310221</guid>
      <dc:creator>munitech4u</dc:creator>
      <dc:date>2016-04-14T09:57:52Z</dc:date>
    </item>
  </channel>
</rss>

