<?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: sqlloop question in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/sqlloop-question/m-p/189558#M35766</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This isn't a proc transpose problem.&amp;nbsp; Do you have a macro variable that already lets you know how many variables you have? or a naming convention for your new variables?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It's fairly easy in a data step, but i'm guessing that you have different variables in each and want to automate that somehow.&amp;nbsp; But do you really need this, I'd imagine you'd first want to merge/join your twenty tables and then do something like this?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;array vars(3) x12 x13 x8;&lt;/P&gt;&lt;P&gt;array vars_new(3) indicator_x12 indicator_x13 indicator_x8;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;do i=1 to dim(vars);&lt;/P&gt;&lt;P&gt;ifn(vars(i)=0, 0,1);&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 27 Feb 2014 22:51:57 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2014-02-27T22:51:57Z</dc:date>
    <item>
      <title>sqlloop question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sqlloop-question/m-p/189555#M35763</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all--&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Still new to SAS, and extremely new to macros. I've been using macros to loop through proc reg and proc sql just fine, but I've run into a snag. I ran proc reg on all of my dependent variables with &lt;EM&gt;different&lt;/EM&gt; sets of independent variables (I performed variable elimination on each dependent variable) to get all possible models with their AIC values. Now I have models with different variables, e.g. Y1 = X1 X3 and Y2 = X1 X2 X4, etc. I have output tables that I'm trying to manipulate to obtain akaike weights and averaged parameter estimates. In order to do this, I have to use the case expression (colored blue in the code below) to create a new set of columns for each individual variable where if parameter X is present in the model, it gets a value of 1, if not it gets a value of 0.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I included an attached table as an example of one of 20 tables I need to get through this. For this particular table I need 3 new columns, one for each parameter.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can anyone point me in the right direction here? I tried to create some %let statements, but I have to use an equal sign, which it won't accept. I'm sure there's a more efficient way to do this than writing out the code for each of my 20 dependent variables by hand. Any help would be appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro sqlloop(num);&lt;/P&gt;&lt;P&gt;%do i=1 %to &amp;amp;num;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table Y&amp;amp;i.parmestpresence as&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;select _model_, &amp;amp;&amp;amp;col&amp;amp;i.,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;case&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;when X12=0 then 0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;else 1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;end as X12IG label='X12 I(j)G(i)' format=best.,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;case&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;when X13=0 then 0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;else 1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;end as X13IG label='X13 I(j)G(i)' format=best.,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;_aicc_, _deltaaicc_, _wi_ from Y&amp;amp;i.akaikeweight;&lt;/P&gt;&lt;P&gt;title 'Y&amp;amp;i. Ij(gi)';&lt;/P&gt;&lt;P&gt;select * from Y&amp;amp;i.parmestpresence;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%sqlloop(20)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Feb 2014 22:00:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sqlloop-question/m-p/189555#M35763</guid>
      <dc:creator>econdon</dc:creator>
      <dc:date>2014-02-27T22:00:53Z</dc:date>
    </item>
    <item>
      <title>Re: sqlloop question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sqlloop-question/m-p/189556#M35764</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If your datasets aren't too big, you may want to consider BY processing instead.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The answer to your direct question depends on how your data looks, usually a proc transpose is what you'll need to give you 1's and then you can fill in the missing with 0.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Feb 2014 22:05:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sqlloop-question/m-p/189556#M35764</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-02-27T22:05:27Z</dc:date>
    </item>
    <item>
      <title>Re: sqlloop question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sqlloop-question/m-p/189557#M35765</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Reeza--&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My data sets are pretty small, but I'm not sure what you mean by BY processing. Is that something I should do in proc sql, or should i move to proc transpose? I've never used proc transpose, but I'll look into it now.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Lizzie&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Feb 2014 22:39:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sqlloop-question/m-p/189557#M35765</guid>
      <dc:creator>econdon</dc:creator>
      <dc:date>2014-02-27T22:39:46Z</dc:date>
    </item>
    <item>
      <title>Re: sqlloop question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sqlloop-question/m-p/189558#M35766</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This isn't a proc transpose problem.&amp;nbsp; Do you have a macro variable that already lets you know how many variables you have? or a naming convention for your new variables?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It's fairly easy in a data step, but i'm guessing that you have different variables in each and want to automate that somehow.&amp;nbsp; But do you really need this, I'd imagine you'd first want to merge/join your twenty tables and then do something like this?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;array vars(3) x12 x13 x8;&lt;/P&gt;&lt;P&gt;array vars_new(3) indicator_x12 indicator_x13 indicator_x8;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;do i=1 to dim(vars);&lt;/P&gt;&lt;P&gt;ifn(vars(i)=0, 0,1);&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Feb 2014 22:51:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sqlloop-question/m-p/189558#M35766</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-02-27T22:51:57Z</dc:date>
    </item>
    <item>
      <title>Re: sqlloop question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sqlloop-question/m-p/189559#M35767</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Example of By group processing:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data=sashelp.class; by sex;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc reg data=class;&lt;/P&gt;&lt;P&gt;by sex;&lt;/P&gt;&lt;P&gt;model weight=height age;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Feb 2014 22:52:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sqlloop-question/m-p/189559#M35767</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-02-27T22:52:53Z</dc:date>
    </item>
    <item>
      <title>Re: sqlloop question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sqlloop-question/m-p/189560#M35768</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Reeza, let me give this a try on just one table. I do have the different variable names as macro statements, so I should be able to make that loop.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Feb 2014 23:02:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sqlloop-question/m-p/189560#M35768</guid>
      <dc:creator>econdon</dc:creator>
      <dc:date>2014-02-27T23:02:16Z</dc:date>
    </item>
    <item>
      <title>Re: sqlloop question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sqlloop-question/m-p/189561#M35769</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Reeza--&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm getting an error code--I think I'm missing something at the end there. Was wondering if you had an insight?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; data y7deltaaiccpres;&lt;/P&gt;&lt;P&gt;2776&amp;nbsp; set y7deltaaicc;&lt;/P&gt;&lt;P&gt;2777&amp;nbsp; array vars(6) x10 x2 x3 x4 x5 x6;&lt;/P&gt;&lt;P&gt;2778&amp;nbsp; array vars_new(6) indicator_x10 indicator_x2 indicator_x3 indicator_x4 indicator_x5&lt;/P&gt;&lt;P&gt;2778! indicator_x6;&lt;/P&gt;&lt;P&gt;2779&lt;/P&gt;&lt;P&gt;2780&amp;nbsp; do i=1 to dim(vars);&lt;/P&gt;&lt;P&gt;2781&amp;nbsp; ifn(vars(i)=0,=0,=1);&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 22&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;ERROR: Undeclared array referenced: ifn.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000;"&gt;2781&amp;nbsp; ifn(vars(i)=0,=0,=1);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 22&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&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;&amp;nbsp; a numeric constant, a datetime constant, a missing value, INPUT, PUT.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2781&amp;nbsp; ifn(vars(i)=0,=0,=1);&lt;/P&gt;&lt;P&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -&lt;/P&gt;&lt;P&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 22&lt;/P&gt;&lt;P&gt;ERROR 22-322: Syntax error, expecting one of the following: +, =.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2781&amp;nbsp; ifn(vars(i)=0,=0,=1);&lt;/P&gt;&lt;P&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -&lt;/P&gt;&lt;P&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 76&lt;/P&gt;&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2782&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;2783&amp;nbsp; run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Feb 2014 23:26:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sqlloop-question/m-p/189561#M35769</guid>
      <dc:creator>econdon</dc:creator>
      <dc:date>2014-02-27T23:26:58Z</dc:date>
    </item>
    <item>
      <title>Re: sqlloop question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sqlloop-question/m-p/189562#M35770</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The function should be&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;vars_new(i)=ifn(vars(i)=0, 0, 1) &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;No equal signs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you're on a version of SAS that's older then try something like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if vars(i)=0 then vars_new(i)=0;&lt;/P&gt;&lt;P&gt;else vars_new(i)=1;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Feb 2014 23:30:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sqlloop-question/m-p/189562#M35770</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-02-27T23:30:31Z</dc:date>
    </item>
    <item>
      <title>Re: sqlloop question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sqlloop-question/m-p/189563#M35771</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Oops, sorry. I was just messing around, the old code without equal signs didn't work either.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The new code did give me an output, but all the new cells have 1's in them. Not what I'm looking for...still messing around here. Thanks for your help, this is getting me closer!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Feb 2014 23:42:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sqlloop-question/m-p/189563#M35771</guid>
      <dc:creator>econdon</dc:creator>
      <dc:date>2014-02-27T23:42:09Z</dc:date>
    </item>
    <item>
      <title>Re: sqlloop question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sqlloop-question/m-p/189564#M35772</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Oh HA! The original table did not have 0's, it had blank cells when a parameter was missing. I flipped the if/then statement to&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if vars(i)&amp;lt;&amp;gt;0 then vars_new(i)=1;&lt;/P&gt;&lt;P&gt;else vars_new(i)=0;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and that did the trick. I think I see the next step from here. Thanks for all your help!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Feb 2014 23:47:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sqlloop-question/m-p/189564#M35772</guid>
      <dc:creator>econdon</dc:creator>
      <dc:date>2014-02-27T23:47:24Z</dc:date>
    </item>
  </channel>
</rss>

