<?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: How do I efficiently divide all numeric variables in my dataset against all other numeric variab in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-efficiently-divide-all-numeric-variables-in-my-dataset/m-p/251320#M47465</link>
    <description>&lt;P&gt;Straightforward programming, no macros :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id $ a b c d e;
datalines;
Ballard 1 2 3 4 5 
Reeza 6 7 8 9 0 
Alan 2 3 4 5 .
;

data long;
set have;
array _num _numeric_;
obs = _n_;
do vorder = 1 to dim(_num);
    vname = vname(_num{vorder});
    value = _num{vorder};
    output;
    end;
keep _character_ obs vorder value;
run;

proc sql;
create table longRatios as
select 
    num.obs,
    num.id,
    cats(num.vname, "_div_", div.vname) as ratioName,
    case
        when div.value = 0 then .
        when missing(num.value) then .
        when missing(div.value) then .
        else num.value / div.value 
        end as ratio format=5.2
from 
    long as num inner join 
    long as div on num.obs=div.obs and num.vname ne div.vname
order by obs, num.vorder, div.vorder;
quit;

proc transpose data=longRatios out=ratios(drop=_name_ obs);
by obs id;
var ratio;
id ratioName;
run;

proc print data=ratios noobs; run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 20 Feb 2016 04:50:06 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2016-02-20T04:50:06Z</dc:date>
    <item>
      <title>How do I efficiently divide all numeric variables in my dataset against all other numeric variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-efficiently-divide-all-numeric-variables-in-my-dataset/m-p/251272#M47439</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I write a macro to efficiently divide all of the numeric variables in my dataset against&lt;/P&gt;&lt;P&gt;all other numeric variables in my dataset? &amp;nbsp;For example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Var1 Var2 Var3&lt;/P&gt;&lt;P&gt;1. &amp;nbsp; &amp;nbsp; &amp;nbsp; 2. &amp;nbsp; &amp;nbsp; 4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Would yield:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Var1divVar2 = .5&lt;/P&gt;&lt;P&gt;Var1divVar3 = .25&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!!&lt;/P&gt;</description>
      <pubDate>Fri, 19 Feb 2016 20:32:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-efficiently-divide-all-numeric-variables-in-my-dataset/m-p/251272#M47439</guid>
      <dc:creator>AlanCT</dc:creator>
      <dc:date>2016-02-19T20:32:11Z</dc:date>
    </item>
    <item>
      <title>Re: How do I efficiently divide all numeric variables in my dataset against all other numeric variab</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-efficiently-divide-all-numeric-variables-in-my-dataset/m-p/251282#M47445</link>
      <description>&lt;P&gt;Can you provide some more sample data and output?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm curious as to what the logic is behind this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, do you have SAS IML, this sounds a lot like a matrix operation.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Feb 2016 20:53:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-efficiently-divide-all-numeric-variables-in-my-dataset/m-p/251282#M47445</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-02-19T20:53:35Z</dc:date>
    </item>
    <item>
      <title>Re: How do I efficiently divide all numeric variables in my dataset against all other numeric variab</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-efficiently-divide-all-numeric-variables-in-my-dataset/m-p/251285#M47447</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;really nothing more to describe.&lt;/P&gt;&lt;P&gt;i just need to create ratios between each and every variable in a large dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd appreciate any advice on how to do this efficiently.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks!,&lt;/P&gt;</description>
      <pubDate>Fri, 19 Feb 2016 20:59:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-efficiently-divide-all-numeric-variables-in-my-dataset/m-p/251285#M47447</guid>
      <dc:creator>AlanCT</dc:creator>
      <dc:date>2016-02-19T20:59:33Z</dc:date>
    </item>
    <item>
      <title>Re: How do I efficiently divide all numeric variables in my dataset against all other numeric variab</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-efficiently-divide-all-numeric-variables-in-my-dataset/m-p/251286#M47448</link>
      <description>&lt;P&gt;i don't have iml&lt;/P&gt;</description>
      <pubDate>Fri, 19 Feb 2016 21:00:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-efficiently-divide-all-numeric-variables-in-my-dataset/m-p/251286#M47448</guid>
      <dc:creator>AlanCT</dc:creator>
      <dc:date>2016-02-19T21:00:32Z</dc:date>
    </item>
    <item>
      <title>Re: How do I efficiently divide all numeric variables in my dataset against all other numeric variab</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-efficiently-divide-all-numeric-variables-in-my-dataset/m-p/251301#M47456</link>
      <description>&lt;P&gt;Is this between values only on one row (observation) of a data set or are you looking to do this calculation across rows as well?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the last is what you want I suggest that provide an example with 3 or 4 variables, 3 or 4 rows of input data and what you expect the output to look like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have currently 10 variables then you are going to end up with 45 new variables. Is that what you intend?&lt;/P&gt;</description>
      <pubDate>Fri, 19 Feb 2016 22:19:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-efficiently-divide-all-numeric-variables-in-my-dataset/m-p/251301#M47456</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-02-19T22:19:15Z</dc:date>
    </item>
    <item>
      <title>Re: How do I efficiently divide all numeric variables in my dataset against all other numeric variab</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-efficiently-divide-all-numeric-variables-in-my-dataset/m-p/251315#M47464</link>
      <description>&lt;P&gt;First, you need to do your homework. &amp;nbsp;Do you want Var1DivVar2 as well as Var2DivVar1? &amp;nbsp;If the denominator is 0, what would you like the result to be? &amp;nbsp;If either the numerator or denominator is missing, what would you like the result to be? &amp;nbsp;If you are starting with 100 numeric variables, are you prepared to end up with a data set with 10,000 variables? &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What variable names will you use to hold the results? &amp;nbsp;If you start with variable names that are 20 characters long, you won't have room to create a new variable name that is 40 characters long. &amp;nbsp;So how will you map the ratios to the variables that went into the calculations?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Truthfully, the programming is fairly straightforward and may not even involve macros. &amp;nbsp;It's the preparation that is difficult.&lt;/P&gt;</description>
      <pubDate>Sat, 20 Feb 2016 01:07:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-efficiently-divide-all-numeric-variables-in-my-dataset/m-p/251315#M47464</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-02-20T01:07:45Z</dc:date>
    </item>
    <item>
      <title>Re: How do I efficiently divide all numeric variables in my dataset against all other numeric variab</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-efficiently-divide-all-numeric-variables-in-my-dataset/m-p/251320#M47465</link>
      <description>&lt;P&gt;Straightforward programming, no macros :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id $ a b c d e;
datalines;
Ballard 1 2 3 4 5 
Reeza 6 7 8 9 0 
Alan 2 3 4 5 .
;

data long;
set have;
array _num _numeric_;
obs = _n_;
do vorder = 1 to dim(_num);
    vname = vname(_num{vorder});
    value = _num{vorder};
    output;
    end;
keep _character_ obs vorder value;
run;

proc sql;
create table longRatios as
select 
    num.obs,
    num.id,
    cats(num.vname, "_div_", div.vname) as ratioName,
    case
        when div.value = 0 then .
        when missing(num.value) then .
        when missing(div.value) then .
        else num.value / div.value 
        end as ratio format=5.2
from 
    long as num inner join 
    long as div on num.obs=div.obs and num.vname ne div.vname
order by obs, num.vorder, div.vorder;
quit;

proc transpose data=longRatios out=ratios(drop=_name_ obs);
by obs id;
var ratio;
id ratioName;
run;

proc print data=ratios noobs; run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 20 Feb 2016 04:50:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-efficiently-divide-all-numeric-variables-in-my-dataset/m-p/251320#M47465</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-02-20T04:50:06Z</dc:date>
    </item>
    <item>
      <title>Re: How do I efficiently divide all numeric variables in my dataset against all other numeric variab</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-efficiently-divide-all-numeric-variables-in-my-dataset/m-p/251325#M47466</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;divide(num.value,div.value) as ratio format 5.2&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Maybe&lt;/P&gt;</description>
      <pubDate>Sat, 20 Feb 2016 12:42:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-efficiently-divide-all-numeric-variables-in-my-dataset/m-p/251325#M47466</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2016-02-20T12:42:55Z</dc:date>
    </item>
  </channel>
</rss>

