<?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: PROC SQL SELECT in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-SELECT/m-p/512566#M138076</link>
    <description>&lt;P&gt;You can do a left join and use COALESCE() function, which will return non-missing value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table test as
select distinct a.record_id,a.inddato,coalesce(a.time,b.xx) as time
from one as a
left join two as b
	on a.inddato=b.inddato and a.record_id=b.record_id 
; quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Alternatively you can also use update statement in data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=one;
by record_id inddato;
proc sort data=two;
by record_id inddato;
run;

data one;
update one two(rename=(xx=time));
by record_id inddato;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 13 Nov 2018 15:03:48 GMT</pubDate>
    <dc:creator>SuryaKiran</dc:creator>
    <dc:date>2018-11-13T15:03:48Z</dc:date>
    <item>
      <title>PROC SQL SELECT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-SELECT/m-p/512551#M138072</link>
      <description>&lt;P&gt;Dear SAS experts&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset x1 and dataset x2. I would like for specific variables of x1 to take the value of other variables in x2 under specific conditions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is my suggestion for programming. I hope this makes sense.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data one;&lt;BR /&gt;input record_id inddato time;&lt;BR /&gt;datalines;&lt;BR /&gt;1 123 4&lt;BR /&gt;1 125 7&lt;BR /&gt;2 345&lt;BR /&gt;2 145 12&lt;BR /&gt;4 125&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;data two;&lt;BR /&gt;input record_id inddato xx;&lt;BR /&gt;datalines;&lt;BR /&gt;2 345 12&lt;BR /&gt;4 125 17&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table test as&lt;BR /&gt;select distinct a.* from two&lt;BR /&gt;join b.one&lt;BR /&gt;on a.inddato=b.inddato and a.record_id=b.record_id and record_id in (2,4)&lt;BR /&gt;then b.time=a.xx&lt;/P&gt;&lt;P&gt;; quit;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data want;&lt;BR /&gt;input record_id inddato time;&lt;BR /&gt;datalines;&lt;BR /&gt;1 123 4&lt;BR /&gt;1 125 7&lt;BR /&gt;2 345 12&lt;BR /&gt;2 145 12&lt;BR /&gt;4 125 17&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However this does not work. Any suggestions?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Solvej&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Nov 2018 14:36:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-SELECT/m-p/512551#M138072</guid>
      <dc:creator>Solvej</dc:creator>
      <dc:date>2018-11-13T14:36:59Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL SELECT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-SELECT/m-p/512566#M138076</link>
      <description>&lt;P&gt;You can do a left join and use COALESCE() function, which will return non-missing value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table test as
select distinct a.record_id,a.inddato,coalesce(a.time,b.xx) as time
from one as a
left join two as b
	on a.inddato=b.inddato and a.record_id=b.record_id 
; quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Alternatively you can also use update statement in data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=one;
by record_id inddato;
proc sort data=two;
by record_id inddato;
run;

data one;
update one two(rename=(xx=time));
by record_id inddato;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 13 Nov 2018 15:03:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-SELECT/m-p/512566#M138076</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-11-13T15:03:48Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL SELECT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-SELECT/m-p/512570#M138077</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input record_id inddato time;
datalines;
1 123 4
1 125 7
2 345 .
2 145 12
4 125
;
run;
data two;
input record_id inddato xx;
datalines;
2 345 12
4 125 17
;
run;

data want;
merge one two(rename=(xx=time));
by record_id;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;SAS Output&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;TABLE class="systitleandfootercontainer" border="0" summary="Page Layout" width="100%" frame="void" rules="none" cellspacing="1" cellpadding="1"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="c systemtitle"&gt;The SAS System&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;BR /&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;COLGROUP&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r header" scope="col"&gt;record_id&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;inddato&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;time&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;123&lt;/TD&gt;
&lt;TD class="r data"&gt;4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;125&lt;/TD&gt;
&lt;TD class="r data"&gt;7&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;TD class="r data"&gt;345&lt;/TD&gt;
&lt;TD class="r data"&gt;12&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;TD class="r data"&gt;145&lt;/TD&gt;
&lt;TD class="r data"&gt;12&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;4&lt;/TD&gt;
&lt;TD class="r data"&gt;125&lt;/TD&gt;
&lt;TD class="r data"&gt;17&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Tue, 13 Nov 2018 15:11:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-SELECT/m-p/512570#M138077</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-11-13T15:11:56Z</dc:date>
    </item>
  </channel>
</rss>

