<?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: SAS MACRO - Find corresponding variable name which matches value in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-MACRO-Find-corresponding-variable-name-which-matches-value/m-p/322627#M21577</link>
    <description>&lt;P&gt;Hi Koen,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just a few quick queries on this piece of code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it the case that when I'm running this, that I'll have to change the 62.5 everytime I want to find a different value?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;tot_minus_alt_tot = 62.5;&lt;/PRE&gt;&lt;P&gt;Given I've 100,000 indiviudals it is the case that tot_minus_alt_tot could be completly different for each individual.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sean&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 05 Jan 2017 11:15:23 GMT</pubDate>
    <dc:creator>Sean_OConnor</dc:creator>
    <dc:date>2017-01-05T11:15:23Z</dc:date>
    <item>
      <title>SAS MACRO - Find corresponding variable name which matches value</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-MACRO-Find-corresponding-variable-name-which-matches-value/m-p/322433#M21563</link>
      <description>&lt;P&gt;Folks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Given my lack of knowledge of utilising macros in SAS I'd appreciate some advice or at least guidance to some reading material.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;At present I've information on &amp;nbsp;over 1,000,000 individuals which each individual having over 400 variables. Within my dataset there is a variable called tot_aggregate. Furthermore, I've been given infromation as to 9 variables (x1...x400) which make up tot_aggregate. When I sum these to create my alt_tot_aggregate and compare them to the tot_aggregate variable I notice in circa 100,000 cases they do not match.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In other words there is some other variable which I am not accounting for in my estimation of alt_tot_aggregate. Thus, what I would like to do is the following.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Create a macro which searches variable to variable to find a matching value and creates a new variable called missing_var_name which inserts the name of the missing variable within.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A quick illustration may provide better insight.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;id x1 x2 x3.......x400 &amp;nbsp;tot_aggregate &amp;nbsp;alt_tot_aggregate (x1, x45, x354) missing_var_name&lt;/P&gt;&lt;P&gt;1 &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; 600 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;523 &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; &amp;nbsp; x56&lt;/P&gt;&lt;P&gt;2 &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; 1500 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1500 &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; &amp;nbsp; .&lt;/P&gt;&lt;P&gt;3 &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; 230 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;230 &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; &amp;nbsp; &amp;nbsp; .&lt;/P&gt;&lt;P&gt;4 &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;563 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;200 &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; &amp;nbsp; &amp;nbsp;x236&lt;/P&gt;&lt;P&gt;5 &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;6 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not even sure if such a thing is possible but would welcome any advice or guidance.&lt;/P&gt;&lt;P&gt;I'm aware that I'm making the assumption that the missing values are only due to one variable,&lt;/P&gt;&lt;P&gt;however, from eyeballing a few examples I'm confident that it's only one which is missing. &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;</description>
      <pubDate>Wed, 04 Jan 2017 16:06:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-MACRO-Find-corresponding-variable-name-which-matches-value/m-p/322433#M21563</guid>
      <dc:creator>Sean_OConnor</dc:creator>
      <dc:date>2017-01-04T16:06:25Z</dc:date>
    </item>
    <item>
      <title>Re: SAS MACRO - Find corresponding variable name which matches value</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-MACRO-Find-corresponding-variable-name-which-matches-value/m-p/322440#M21564</link>
      <description>&lt;P&gt;Hello Sean_OConnor,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This little program may help you.&lt;/P&gt;
&lt;P&gt;The VNAME function is what you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data abc(drop=i);
 LENGTH missing_var_name $ 32;
 set sashelp.class (rename=(age   =x1
                            height=x2
                            weight=x3));
 array xx(3) x1-x3;
 tot_minus_alt_tot = 62.5;
 do i = 1 to dim(xx);
  if xx(i) = tot_minus_alt_tot 
    then missing_var_name = vname(xx(i));
 end;
run;
/* end of program */
 &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It would be possible to write a program that, per observation and for a given total, enumerates all possible sums of variables that lead to this total.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;
&lt;P&gt;Brussels&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jan 2017 17:06:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-MACRO-Find-corresponding-variable-name-which-matches-value/m-p/322440#M21564</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2017-01-04T17:06:56Z</dc:date>
    </item>
    <item>
      <title>Re: SAS MACRO - Find corresponding variable name which matches value</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-MACRO-Find-corresponding-variable-name-which-matches-value/m-p/322441#M21565</link>
      <description>&lt;P&gt;Sean,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The good news:&amp;nbsp; you don't need to learn anything about macros to make this happen.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The bad news:&amp;nbsp; you do have to learn about arrays, and at an intermediate (not beginner) level.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's an example of the type of code that might appear in a DATA step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;length missing_var_name $ 32;&lt;/P&gt;
&lt;P&gt;array x {400} x1-x400;&lt;/P&gt;
&lt;P&gt;if tot_aggregate ne alt_tot_aggregate then do k=2 to 44, 46 to 353, 355 to 400;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if tot_aggregate = alt_tot_aggregate + x{k} then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; missing_var_name = vname(x{k});&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that this may be an iterative process if you are missing 2 variables instead of one.&amp;nbsp; First locate one of the missing variables and add it in to ALT_TOT_AGGREGATE.&amp;nbsp; Then repeat the entire process to locate the other missing variable.&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jan 2017 17:07:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-MACRO-Find-corresponding-variable-name-which-matches-value/m-p/322441#M21565</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-01-04T17:07:40Z</dc:date>
    </item>
    <item>
      <title>Re: SAS MACRO - Find corresponding variable name which matches value</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-MACRO-Find-corresponding-variable-name-which-matches-value/m-p/322627#M21577</link>
      <description>&lt;P&gt;Hi Koen,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just a few quick queries on this piece of code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it the case that when I'm running this, that I'll have to change the 62.5 everytime I want to find a different value?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;tot_minus_alt_tot = 62.5;&lt;/PRE&gt;&lt;P&gt;Given I've 100,000 indiviudals it is the case that tot_minus_alt_tot could be completly different for each individual.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sean&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jan 2017 11:15:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-MACRO-Find-corresponding-variable-name-which-matches-value/m-p/322627#M21577</guid>
      <dc:creator>Sean_OConnor</dc:creator>
      <dc:date>2017-01-05T11:15:23Z</dc:date>
    </item>
    <item>
      <title>Re: SAS MACRO - Find corresponding variable name which matches value</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-MACRO-Find-corresponding-variable-name-which-matches-value/m-p/322637#M21578</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;in your code&lt;/P&gt;
&lt;P&gt;tot_minus_alt_tot = 62.5;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;would become:&lt;/P&gt;
&lt;P&gt;tot_minus_alt_tot =&amp;nbsp;( tot_aggregate -&amp;nbsp;alt_tot_aggregate ) ;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That way tot_minus_alt_tot could be completely different for each individual. No manual intervention from your side required.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jan 2017 11:44:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-MACRO-Find-corresponding-variable-name-which-matches-value/m-p/322637#M21578</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2017-01-05T11:44:13Z</dc:date>
    </item>
    <item>
      <title>Re: SAS MACRO - Find corresponding variable name which matches value</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-MACRO-Find-corresponding-variable-name-which-matches-value/m-p/323024#M21599</link>
      <description>&lt;P&gt;A further query relating to the following excellent code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data abc(drop=i);
 LENGTH missing_var_name $ 32;
 set sashelp.class (rename=(age   =x1
                            height=x2
                            weight=x3));
 array xx(3) x1-x3;
 tot_minus_alt_tot = (total_income - alt_tot_income);
 do i = 1 to dim(xx);
  if xx(i) = tot_minus_alt_tot 
    then missing_var_name = vname(xx(i));
 end;
run;
/* end of program */&lt;/PRE&gt;&lt;P&gt;Initially, I made the assumption that my missing variable is due to only one observation. However, in some cases the same value may be in place in numerous different variables.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it possible to amend the code above to create a second missing_var_name &amp;nbsp;third missing_var_name and so on, each time a match is found?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Furthermore, it could be the case that a number of variables aggregated together could create the missing observations, but I imagine it would be extremely difficult to extend the code to aggregate different combinations of variables to look for a match?&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jan 2017 16:18:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-MACRO-Find-corresponding-variable-name-which-matches-value/m-p/323024#M21599</guid>
      <dc:creator>Sean_OConnor</dc:creator>
      <dc:date>2017-01-06T16:18:23Z</dc:date>
    </item>
    <item>
      <title>Re: SAS MACRO - Find corresponding variable name which matches value</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-MACRO-Find-corresponding-variable-name-which-matches-value/m-p/323052#M21601</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your 1st question:&lt;/P&gt;
&lt;P&gt;Is it possible to amend the code above to create a second missing_var_name &amp;nbsp;third missing_var_name and so on, each time a match is found?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My answer:&lt;/P&gt;
&lt;P&gt;Yes.&lt;/P&gt;
&lt;P&gt;See below program (untested, but it should bring you the answer).&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;The LENGTH statement shows another length for missing_var_name ($ 1500 instead of $ 32).&lt;/LI&gt;
&lt;LI&gt;missing_var_name is initialized on missing ('') for every observation.&lt;/LI&gt;
&lt;LI&gt;Each time a match is detected, an additional variable name is added to missing_var_name&amp;nbsp;and the separator with the previous variable name is an equality sign (=). No override anymore as in the previous program.&lt;/LI&gt;
&lt;/UL&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data abc(drop=i);
 LENGTH missing_var_name $ 1500;
 set sashelp.class (rename=(age   =x1
                            height=x2
                            weight=x3));
 array xx(3) x1-x3;
 missing_var_name='';
 tot_minus_alt_tot = (total_income - alt_tot_income);
 do i = 1 to dim(xx);
  if xx(i) = tot_minus_alt_tot 
    then missing_var_name = strip(missing_var_name)!!'='!!strip(vname(xx(i)));
 end;
run;
/* end of program */
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your 2nd question:&lt;/P&gt;
&lt;P&gt;Furthermore, it could be the case that a number of variables aggregated together could create the missing observations, but I imagine it would be extremely difficult to extend the code to aggregate different combinations of variables to look for a match?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My answer:&lt;/P&gt;
&lt;P&gt;If you have SAS/OR (SAS for Operations Research (mathematical programming)) I can extend the code so that you get all possible solutions / sums that result in a given total, the total being tot_minus_alt_tot = (total_income - alt_tot_income). It's not really 'extending the code', rather it is writing a completely different program in our algebraïc modelling language (PROC OPTMODEL) and then solving with our CLP solver (constraint logic programming (CLP) solver in the OPTMODEL procedure).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck,&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;
&lt;P&gt;Brussels&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jan 2017 17:46:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SAS-MACRO-Find-corresponding-variable-name-which-matches-value/m-p/323052#M21601</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2017-01-06T17:46:01Z</dc:date>
    </item>
  </channel>
</rss>

