<?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: Determine which variable to use based on column values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Determine-which-variable-to-use-based-on-column-values/m-p/562681#M157640</link>
    <description>&lt;P&gt;Are you saying that the names of the variables can change over time?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If not then just code an IF statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if type='1a1' then ratio = (_1a_val * 100)/360;
else if type='1b1' then ratio = (_1b_val * 100)/360;
else if type='1c1' then ratio = (_1c_val * 100)/360;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you can change how TYPE is coded then it would be even easier.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you make TYPE an integer from 1 to 3 then you could just use an array.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array value _1a_val _1b_val _1c_val ;
ratio = (value[type] * 100)/360;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 30 May 2019 19:28:42 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2019-05-30T19:28:42Z</dc:date>
    <item>
      <title>Determine which variable to use based on column values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determine-which-variable-to-use-based-on-column-values/m-p/562678#M157639</link>
      <description>&lt;P&gt;Dear SAS users,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a data set similar to the one below. I want to calculate "ratio" based values specified on the 'type' variable without hard coding the type values. since the type could be different month to month.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;For example:&lt;/P&gt;
&lt;P&gt;for row 1:&lt;/P&gt;
&lt;P&gt;ratio = (_1a_val * 100)/360;&lt;/P&gt;
&lt;P&gt;row 3: &lt;BR /&gt;ratio = (_1b_val * 100)/360;&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;data have; 
input class $ type $ month _1a_val _1b_val _1c_val;
datalines; 
Plas-1 1a1 0 2.5 3.5 4.5
Plas-1 1a1 1 2.5 3.5 4.5
Plas-1 1b1 0 2.5 3.5 4.5
Plas-1 1b1 1 2.5 3.5 4.5
Plas-1 1c1 0 2.5 3.5 4.5
Plas-1 1c1 1 2.5 3.5 4.5
Plas-1 1c1 2 2.5 3.5 4.5
blod-2 1a1 0 1.5 2.5 3.5
blod-2 1a1 1 1.5 2.5 3.5
blod-2 1b1 0 1.5 2.5 3.5
blod-2 1b1 1 1.5 2.5 3.5
blod-2 1b1 2 1.5 2.5 3.5
blod-2 1c1 0 1.5 2.5 3.5
blod-2 1c1 1 1.5 2.5 3.5
blod-2 1c1 2 1.5 2.5 3.5
;
run;&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;Here is the result. I want&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;class	type	month	_1a_val	_1b_val	_1c_val	ratio
Plas-1	1a1	0	2.5	3.5	4.5	0.6944444444
Plas-1	1a1	1	2.5	3.5	4.5	0.6944444444
Plas-1	1b1	0	2.5	3.5	4.5	0.9722222222
Plas-1	1b1	1	2.5	3.5	4.5	0.9722222222
Plas-1	1c1	0	2.5	3.5	4.5	1.25
Plas-1	1c1	1	2.5	3.5	4.5	1.25
Plas-1	1c1	2	2.5	3.5	4.5	1.25
blod-2	1a1	0	1.5	2.5	3.5	0.4166666667
blod-2	1a1	1	1.5	2.5	3.5	0.4166666667
blod-2	1b1	0	1.5	2.5	3.5	0.6944444444
blod-2	1b1	1	1.5	2.5	3.5	0.6944444444
blod-2	1b1	2	1.5	2.5	3.5	0.6944444444
blod-2	1c1	0	1.5	2.5	3.5	0.9722222222
blod-2	1c1	1	1.5	2.5	3.5	0.9722222222
blod-2	1c1	2	1.5	2.5	3.5	0.9722222222&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 May 2019 19:20:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determine-which-variable-to-use-based-on-column-values/m-p/562678#M157639</guid>
      <dc:creator>zqkal</dc:creator>
      <dc:date>2019-05-30T19:20:19Z</dc:date>
    </item>
    <item>
      <title>Re: Determine which variable to use based on column values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determine-which-variable-to-use-based-on-column-values/m-p/562681#M157640</link>
      <description>&lt;P&gt;Are you saying that the names of the variables can change over time?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If not then just code an IF statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if type='1a1' then ratio = (_1a_val * 100)/360;
else if type='1b1' then ratio = (_1b_val * 100)/360;
else if type='1c1' then ratio = (_1c_val * 100)/360;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you can change how TYPE is coded then it would be even easier.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you make TYPE an integer from 1 to 3 then you could just use an array.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array value _1a_val _1b_val _1c_val ;
ratio = (value[type] * 100)/360;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 30 May 2019 19:28:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determine-which-variable-to-use-based-on-column-values/m-p/562681#M157640</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-05-30T19:28:42Z</dc:date>
    </item>
    <item>
      <title>Re: Determine which variable to use based on column values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determine-which-variable-to-use-based-on-column-values/m-p/562716#M157659</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; 
input class $ type $ month _1a_val _1b_val _1c_val;
datalines; 
Plas-1 1a1 0 2.5 3.5 4.5
Plas-1 1a1 1 2.5 3.5 4.5
Plas-1 1b1 0 2.5 3.5 4.5
Plas-1 1b1 1 2.5 3.5 4.5
Plas-1 1c1 0 2.5 3.5 4.5
Plas-1 1c1 1 2.5 3.5 4.5
Plas-1 1c1 2 2.5 3.5 4.5
blod-2 1a1 0 1.5 2.5 3.5
blod-2 1a1 1 1.5 2.5 3.5
blod-2 1b1 0 1.5 2.5 3.5
blod-2 1b1 1 1.5 2.5 3.5
blod-2 1b1 2 1.5 2.5 3.5
blod-2 1c1 0 1.5 2.5 3.5
blod-2 1c1 1 1.5 2.5 3.5
blod-2 1c1 2 1.5 2.5 3.5
;
run;

data want;
	array ratio_arr{*} _1a_val _1b_val _1c_val;
	i+1;
	do until(last.type);
		set have;
		by class type;

		if first.class then i=1;
	end;

	do until(last.type);
		set have;
		by class type;

		ratio =(ratio_arr[i]*100)/360;
		output;
	end;

	drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 30 May 2019 20:58:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determine-which-variable-to-use-based-on-column-values/m-p/562716#M157659</guid>
      <dc:creator>r_behata</dc:creator>
      <dc:date>2019-05-30T20:58:30Z</dc:date>
    </item>
    <item>
      <title>Re: Determine which variable to use based on column values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determine-which-variable-to-use-based-on-column-values/m-p/562722#M157662</link>
      <description>&lt;P&gt;Thanks for your help. this solution works.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 May 2019 21:23:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determine-which-variable-to-use-based-on-column-values/m-p/562722#M157662</guid>
      <dc:creator>zqkal</dc:creator>
      <dc:date>2019-05-30T21:23:36Z</dc:date>
    </item>
  </channel>
</rss>

