<?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  can I look for a variable value and return the value of another variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-look-for-a-variable-value-and-return-the-value-of/m-p/566462#M159202</link>
    <description>&lt;P&gt;It can be done in a single-pass DATA step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;                         
  input var1 var2 ;                 
  cards ;                           
10 20                               
18 21                               
11 22                               
19 23                               
17 24                               
12 25                               
16 26                               
13 27                               
15 28                               
14 29                               
run ;                               
                                    
data want (drop = _:) ;             
  do until (z) ;                    
    set have end = z ;              
    if var1 &amp;lt;= _max1 then continue ;
    _max1 = var1 ;                  
    _var2 = var2 ;                  
  end ;                             
  var1 = _max1 ;                    
  var2 = _var2 ;                    
run ;                               
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;</description>
    <pubDate>Sun, 16 Jun 2019 18:57:20 GMT</pubDate>
    <dc:creator>hashman</dc:creator>
    <dc:date>2019-06-16T18:57:20Z</dc:date>
    <item>
      <title>How  can I look for a variable value and return the value of another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-look-for-a-variable-value-and-return-the-value-of/m-p/566447#M159197</link>
      <description>&lt;P&gt;Hi, I'm using SAS 9.4. I have a pretty large data set (Millions of data) and I have to find the max value in the VAR1 and then return the value of VAR2, for that max value I found before. Both variables are in the same data set Call B1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I already have created a new data set with the max value of VAR1 (Call US)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;my code for the max values of VAR1 was:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Proc means data=WORK.B1 max nway;&lt;/P&gt;&lt;P&gt;var VAR1;&lt;/P&gt;&lt;P&gt;OUTPUT out = US (drop= _TYPE_ _FREQ_)&lt;/P&gt;&lt;P&gt;Max = / autoname;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much for your help.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 16 Jun 2019 15:54:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-look-for-a-variable-value-and-return-the-value-of/m-p/566447#M159197</guid>
      <dc:creator>Saidaral</dc:creator>
      <dc:date>2019-06-16T15:54:52Z</dc:date>
    </item>
    <item>
      <title>Re: How  can I look for a variable value and return the value of another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-look-for-a-variable-value-and-return-the-value-of/m-p/566451#M159199</link>
      <description>&lt;P&gt;Hi and welcome to the SAS Communities &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an SQL Approach based on the SASHELP.CLASS data set&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
   create table want as
   select name
   from sashelp.class
   having height=max(height);
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So in your case, it will be something like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
   create table want as
   select var2
   from B1
   having var1=max(var1);
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 16 Jun 2019 16:08:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-look-for-a-variable-value-and-return-the-value-of/m-p/566451#M159199</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-06-16T16:08:43Z</dc:date>
    </item>
    <item>
      <title>Re: How  can I look for a variable value and return the value of another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-look-for-a-variable-value-and-return-the-value-of/m-p/566453#M159200</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/278125"&gt;@Saidaral&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi, I'm using SAS 9.4. I have a pretty large data set (Millions of data) and I have to find the max value in the VAR1 and then return the value of VAR2, for that max value I found before. Both variables are in the same data set Call B1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I already have created a new data set with the max value of VAR1 (Call US)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;my code for the max values of VAR1 was:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc means data=WORK.B1 max nway;&lt;/P&gt;
&lt;P&gt;var VAR1;&lt;/P&gt;
&lt;P&gt;OUTPUT out = US (drop= _TYPE_ _FREQ_)&lt;/P&gt;
&lt;P&gt;Max = / autoname;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you so much for your help.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;In PROC MEANS, use the MAXID option of the OUTPUT statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;OUTPUT out = US (drop= _TYPE_ _FREQ_) 
    Max = var1_max 
    maxid(var1(var2))=var2_at_max_var1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 16 Jun 2019 16:49:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-look-for-a-variable-value-and-return-the-value-of/m-p/566453#M159200</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-06-16T16:49:15Z</dc:date>
    </item>
    <item>
      <title>Re: How  can I look for a variable value and return the value of another variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-look-for-a-variable-value-and-return-the-value-of/m-p/566462#M159202</link>
      <description>&lt;P&gt;It can be done in a single-pass DATA step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;                         
  input var1 var2 ;                 
  cards ;                           
10 20                               
18 21                               
11 22                               
19 23                               
17 24                               
12 25                               
16 26                               
13 27                               
15 28                               
14 29                               
run ;                               
                                    
data want (drop = _:) ;             
  do until (z) ;                    
    set have end = z ;              
    if var1 &amp;lt;= _max1 then continue ;
    _max1 = var1 ;                  
    _var2 = var2 ;                  
  end ;                             
  var1 = _max1 ;                    
  var2 = _var2 ;                    
run ;                               
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;</description>
      <pubDate>Sun, 16 Jun 2019 18:57:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-look-for-a-variable-value-and-return-the-value-of/m-p/566462#M159202</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-06-16T18:57:20Z</dc:date>
    </item>
  </channel>
</rss>

