<?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: Resolution of field value to its corresponding column in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Resolution-of-field-value-to-its-corresponding-column/m-p/761649#M241043</link>
    <description>&lt;P&gt;Hello Tom&lt;/P&gt;
&lt;P&gt;Of course the use of array and vvaluex are ideal solutions.&lt;/P&gt;
&lt;P&gt;I was wondering if we could take the distinct of name and val so that we have macro variables created&lt;/P&gt;
&lt;P&gt;which has the VAL corresponding to name.&lt;/P&gt;
&lt;P&gt;BR&lt;/P&gt;</description>
    <pubDate>Sun, 15 Aug 2021 06:18:58 GMT</pubDate>
    <dc:creator>sanalitics</dc:creator>
    <dc:date>2021-08-15T06:18:58Z</dc:date>
    <item>
      <title>Resolution of field value to its corresponding column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolution-of-field-value-to-its-corresponding-column/m-p/761609#M241019</link>
      <description>&lt;P&gt;Following is my query:&lt;/P&gt;
&lt;P&gt;Here is the input dataset "test":&lt;/P&gt;
&lt;P&gt;data test;&lt;BR /&gt;input name $ val $ AA BB CC;&lt;BR /&gt;cards;&lt;BR /&gt;A AA 10 33 44&lt;BR /&gt;B BB 20 21 23&lt;BR /&gt;C CC 30 34 66&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to get the result in the field "Final" that refers to the field in the value of the variable "VAL". Following is the expected table result&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;name VAL AA&amp;nbsp; BB&amp;nbsp; CC&amp;nbsp; Final&lt;BR /&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;AA&amp;nbsp; &amp;nbsp; 10&amp;nbsp; &amp;nbsp;33&amp;nbsp; &amp;nbsp;44&amp;nbsp; 10&lt;BR /&gt;B&amp;nbsp; &amp;nbsp; &amp;nbsp; BB&amp;nbsp; &amp;nbsp; &amp;nbsp;20&amp;nbsp; &amp;nbsp;21&amp;nbsp; 23&amp;nbsp; 21&lt;BR /&gt;C&amp;nbsp; &amp;nbsp; &amp;nbsp; CC&amp;nbsp; &amp;nbsp; &amp;nbsp;30&amp;nbsp; 34&amp;nbsp; 66&amp;nbsp; 66&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Aug 2021 20:57:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolution-of-field-value-to-its-corresponding-column/m-p/761609#M241019</guid>
      <dc:creator>sanalitics</dc:creator>
      <dc:date>2021-08-14T20:57:10Z</dc:date>
    </item>
    <item>
      <title>Re: Resolution of field value to its corresponding column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolution-of-field-value-to-its-corresponding-column/m-p/761611#M241021</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input name $ val $ AA BB CC;
cards;
A AA 10 33 44
B BB 20 21 23
C CC 30 34 66
;
run;

data want(drop=i);
 set test;
 array mynums{*} AA BB CC;
 do i=1 to dim(mynums);
  if vname(mynums(i))=val then Final=mynums(i);
 end;
run;
/* end of program */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Sat, 14 Aug 2021 21:03:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolution-of-field-value-to-its-corresponding-column/m-p/761611#M241021</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2021-08-14T21:03:24Z</dc:date>
    </item>
    <item>
      <title>Re: Resolution of field value to its corresponding column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolution-of-field-value-to-its-corresponding-column/m-p/761612#M241022</link>
      <description>Hello Koen, thank you for the response. Do we have an alternate solution utilizing macro variables ?</description>
      <pubDate>Sat, 14 Aug 2021 21:11:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolution-of-field-value-to-its-corresponding-column/m-p/761612#M241022</guid>
      <dc:creator>sanalitics</dc:creator>
      <dc:date>2021-08-14T21:11:21Z</dc:date>
    </item>
    <item>
      <title>Re: Resolution of field value to its corresponding column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolution-of-field-value-to-its-corresponding-column/m-p/761616#M241024</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/33513"&gt;@sanalitics&lt;/a&gt;&amp;nbsp; +&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/60547"&gt;@sbxkoenk&lt;/a&gt;&amp;nbsp; Wouldn't&amp;nbsp; VVALUEX function be more terser?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input name $ val $ AA BB CC;
cards;
A AA 10 33 44
B BB 20 21 23
C CC 30 34 66
;
run;


data want;
 set test;
 want=vvaluex(val);
run;

proc print noobs;run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.WANT" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="l header" scope="col"&gt;name&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;val&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;AA&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;BB&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;CC&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;want&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;A&lt;/TD&gt;
&lt;TD class="l data"&gt;AA&lt;/TD&gt;
&lt;TD class="r data"&gt;10&lt;/TD&gt;
&lt;TD class="r data"&gt;33&lt;/TD&gt;
&lt;TD class="r data"&gt;44&lt;/TD&gt;
&lt;TD class="l data"&gt;10&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;B&lt;/TD&gt;
&lt;TD class="l data"&gt;BB&lt;/TD&gt;
&lt;TD class="r data"&gt;20&lt;/TD&gt;
&lt;TD class="r data"&gt;21&lt;/TD&gt;
&lt;TD class="r data"&gt;23&lt;/TD&gt;
&lt;TD class="l data"&gt;21&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;C&lt;/TD&gt;
&lt;TD class="l data"&gt;CC&lt;/TD&gt;
&lt;TD class="r data"&gt;30&lt;/TD&gt;
&lt;TD class="r data"&gt;34&lt;/TD&gt;
&lt;TD class="r data"&gt;66&lt;/TD&gt;
&lt;TD class="l data"&gt;66&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Aug 2021 21:21:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolution-of-field-value-to-its-corresponding-column/m-p/761616#M241024</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2021-08-14T21:21:42Z</dc:date>
    </item>
    <item>
      <title>Re: Resolution of field value to its corresponding column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolution-of-field-value-to-its-corresponding-column/m-p/761617#M241025</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/33513"&gt;@sanalitics&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Hello Koen, thank you for the response. Do we have an alternate solution utilizing macro variables ?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;How could a macro variable help?&amp;nbsp; What code would you use the macro variable to create?&amp;nbsp; Remember that the code for a data step cannot change once the step is running.&lt;/P&gt;</description>
      <pubDate>Sat, 14 Aug 2021 21:25:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolution-of-field-value-to-its-corresponding-column/m-p/761617#M241025</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-08-14T21:25:38Z</dc:date>
    </item>
    <item>
      <title>Re: Resolution of field value to its corresponding column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolution-of-field-value-to-its-corresponding-column/m-p/761619#M241027</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/33513"&gt;@sanalitics&lt;/a&gt;,&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/33513"&gt;@sanalitics&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Do we have an alternate solution utilizing macro variables ?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You could use a macro variable to abbreviate the variable list in the DATA step code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let v=AA,BB,CC;

data want;
set test;
Final=choosen(findw("&amp;amp;v",val,',','et'),&amp;amp;v);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But the solution using VVALUEX is still shorter even if you add the INPUT function to convert the character result to a numeric value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Aug 2021 21:56:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolution-of-field-value-to-its-corresponding-column/m-p/761619#M241027</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-08-14T21:56:01Z</dc:date>
    </item>
    <item>
      <title>Re: Resolution of field value to its corresponding column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolution-of-field-value-to-its-corresponding-column/m-p/761649#M241043</link>
      <description>&lt;P&gt;Hello Tom&lt;/P&gt;
&lt;P&gt;Of course the use of array and vvaluex are ideal solutions.&lt;/P&gt;
&lt;P&gt;I was wondering if we could take the distinct of name and val so that we have macro variables created&lt;/P&gt;
&lt;P&gt;which has the VAL corresponding to name.&lt;/P&gt;
&lt;P&gt;BR&lt;/P&gt;</description>
      <pubDate>Sun, 15 Aug 2021 06:18:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolution-of-field-value-to-its-corresponding-column/m-p/761649#M241043</guid>
      <dc:creator>sanalitics</dc:creator>
      <dc:date>2021-08-15T06:18:58Z</dc:date>
    </item>
    <item>
      <title>Re: Resolution of field value to its corresponding column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Resolution-of-field-value-to-its-corresponding-column/m-p/761682#M241051</link>
      <description>&lt;P&gt;I still don't understand how a macro variable helps.&lt;/P&gt;
&lt;P&gt;You could populate a macro variable with the list of variable names and use it to either define the array:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let varlist=AA BB CC;
...
  array vars &amp;amp;varlist;
...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or perhaps to check if the value of the field name variable is valid.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if findw("&amp;amp;varlist",varname,' ','it') then value=input(vvaluex(varname),32.);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 15 Aug 2021 15:00:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Resolution-of-field-value-to-its-corresponding-column/m-p/761682#M241051</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-08-15T15:00:43Z</dc:date>
    </item>
  </channel>
</rss>

