<?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: Equivalent in data step of dataset.variable in proc sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Equivalent-in-data-step-of-dataset-variable-in-proc-sql/m-p/837419#M331096</link>
    <description>&lt;P&gt;Without more information:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data a;
  input year id myvar $1.;
  datalines;
1999 1 a
2000 1 b
1962 2 c
2001 2 d
2002 3 .
2002 3 f
2003 4 .
2003 4 g
2204 5 h
2205 6 i
;
run;

data b;
  input year id myvar $1.;
  datalines;
2002 3 x
2002 3 f
2003 4 y
2003 4 g
2206 8 j
2206 8 k
;
run;

proc sort data=a;
	by year id;
run;

proc sort data=b;
	by year id;
run;
 
data combined;
	merge a (in=z) b;
	by year id;
	if z;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Yields&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 144pt;" border="0" width="192" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" style="height: 15.0pt; width: 48pt;"&gt;year&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;id&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;myvar&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;1962&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;TD&gt;c&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;1999&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD&gt;a&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;2000&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD&gt;b&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;2001&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;TD&gt;d&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;2002&lt;/TD&gt;
&lt;TD align="right"&gt;3&lt;/TD&gt;
&lt;TD&gt;x&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;2002&lt;/TD&gt;
&lt;TD align="right"&gt;3&lt;/TD&gt;
&lt;TD&gt;f&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;2003&lt;/TD&gt;
&lt;TD align="right"&gt;4&lt;/TD&gt;
&lt;TD&gt;y&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;2003&lt;/TD&gt;
&lt;TD align="right"&gt;4&lt;/TD&gt;
&lt;TD&gt;g&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;2204&lt;/TD&gt;
&lt;TD align="right"&gt;5&lt;/TD&gt;
&lt;TD&gt;h&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;2205&lt;/TD&gt;
&lt;TD align="right"&gt;6&lt;/TD&gt;
&lt;TD&gt;i&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you may really want coalesce or something else.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 07 Oct 2022 15:03:59 GMT</pubDate>
    <dc:creator>HB</dc:creator>
    <dc:date>2022-10-07T15:03:59Z</dc:date>
    <item>
      <title>Equivalent in data step of dataset.variable in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Equivalent-in-data-step-of-dataset-variable-in-proc-sql/m-p/837338#M331057</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I did this with proc sql and it works fine.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sql ;
update TABLE as a 

set VAR = case when a.VAR ^= . then a.VAR else (select VAR from TABLE2 as b where a.year = b.year and a.id = b.id) end
;
quit&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;how can i do it in a data step ? Especially specifying condition with VAR from TABLE,..&lt;/P&gt;
&lt;P&gt;proc sql is very slow&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2022 08:23:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Equivalent-in-data-step-of-dataset-variable-in-proc-sql/m-p/837338#M331057</guid>
      <dc:creator>elsfy</dc:creator>
      <dc:date>2022-10-07T08:23:12Z</dc:date>
    </item>
    <item>
      <title>Re: Equivalent in data step of dataset.variable in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Equivalent-in-data-step-of-dataset-variable-in-proc-sql/m-p/837419#M331096</link>
      <description>&lt;P&gt;Without more information:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data a;
  input year id myvar $1.;
  datalines;
1999 1 a
2000 1 b
1962 2 c
2001 2 d
2002 3 .
2002 3 f
2003 4 .
2003 4 g
2204 5 h
2205 6 i
;
run;

data b;
  input year id myvar $1.;
  datalines;
2002 3 x
2002 3 f
2003 4 y
2003 4 g
2206 8 j
2206 8 k
;
run;

proc sort data=a;
	by year id;
run;

proc sort data=b;
	by year id;
run;
 
data combined;
	merge a (in=z) b;
	by year id;
	if z;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Yields&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 144pt;" border="0" width="192" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" style="height: 15.0pt; width: 48pt;"&gt;year&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;id&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;myvar&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;1962&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;TD&gt;c&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;1999&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD&gt;a&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;2000&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;TD&gt;b&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;2001&lt;/TD&gt;
&lt;TD align="right"&gt;2&lt;/TD&gt;
&lt;TD&gt;d&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;2002&lt;/TD&gt;
&lt;TD align="right"&gt;3&lt;/TD&gt;
&lt;TD&gt;x&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;2002&lt;/TD&gt;
&lt;TD align="right"&gt;3&lt;/TD&gt;
&lt;TD&gt;f&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;2003&lt;/TD&gt;
&lt;TD align="right"&gt;4&lt;/TD&gt;
&lt;TD&gt;y&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;2003&lt;/TD&gt;
&lt;TD align="right"&gt;4&lt;/TD&gt;
&lt;TD&gt;g&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;2204&lt;/TD&gt;
&lt;TD align="right"&gt;5&lt;/TD&gt;
&lt;TD&gt;h&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" align="right" style="height: 15.0pt;"&gt;2205&lt;/TD&gt;
&lt;TD align="right"&gt;6&lt;/TD&gt;
&lt;TD&gt;i&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you may really want coalesce or something else.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2022 15:03:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Equivalent-in-data-step-of-dataset-variable-in-proc-sql/m-p/837419#M331096</guid>
      <dc:creator>HB</dc:creator>
      <dc:date>2022-10-07T15:03:59Z</dc:date>
    </item>
    <item>
      <title>Re: Equivalent in data step of dataset.variable in proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Equivalent-in-data-step-of-dataset-variable-in-proc-sql/m-p/837427#M331097</link>
      <description>&lt;P&gt;In a data step if want related records, such as a matching ID variable, to be used then you would MERGE by the matching variable(s). Which will typically involve sorting both data sets by those variables first.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The behavior of Merge for same named variable that are not the by variables is that one value will overwrite others. Which exactly depends on order sets on the MERGE statement. Generally the rightmost ( or last) data set mentioned on the merge statement will contribute the value. Merge however does not work well if the matching variables have multiples in both data sets.&lt;/P&gt;
&lt;P&gt;If need both of the same named variable values for other than replacement then you RENAME the variable in a data set option for one (or more) of the data sets. Then use appropriate named variable for your purpose.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the records in the 'base' data set, the one you are updating, are uniquely identified (meaning no duplicates) of the key variables you can use the UPDATE instead of Merge which has some options that behave differently than merge would. Such as all of the values of 'transaction' set, the one with the new values, all update the same record. Merge with multiple records for the By variable would have multiple output records.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But example of what you actually are working with and desired output may be needed as the behavior of subqueries is not directly available with merge and may require Hash.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2022 15:33:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Equivalent-in-data-step-of-dataset-variable-in-proc-sql/m-p/837427#M331097</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-10-07T15:33:11Z</dc:date>
    </item>
  </channel>
</rss>

