<?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 How to use Proc SQL to assign values from one variable to another in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-Proc-SQL-to-assign-values-from-one-variable-to/m-p/949673#M371455</link>
    <description>&lt;P&gt;Hi SAS Community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let's say I have one SAS dataset with one variable called ID1 with 4 values (1-4) and another variable called ID2 with 4 values (1-3 and then one missing value).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID1&amp;nbsp; &amp;nbsp;ID2&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to fill in the missing value of ID2 with the value in ID1. In data set programming I would usually say IF ID2 = '&amp;nbsp; &amp;nbsp; ' then ID2 = ID1.&amp;nbsp; This will give me the value of 4 for the ID2 missing record.&amp;nbsp; This is easy in the SAS Datastep, but does anyone know how to accomplish the same result using PROC SQL?&amp;nbsp; Please note, I will have to do this over many records and we will be using SQL more often, but at this point if I can have the PROC SQL code that would help me greatly.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried using CASE WHEN but it doesn't seem to look across more than one variable.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 31 Oct 2024 22:31:43 GMT</pubDate>
    <dc:creator>mtakayesu1</dc:creator>
    <dc:date>2024-10-31T22:31:43Z</dc:date>
    <item>
      <title>How to use Proc SQL to assign values from one variable to another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-Proc-SQL-to-assign-values-from-one-variable-to/m-p/949673#M371455</link>
      <description>&lt;P&gt;Hi SAS Community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let's say I have one SAS dataset with one variable called ID1 with 4 values (1-4) and another variable called ID2 with 4 values (1-3 and then one missing value).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID1&amp;nbsp; &amp;nbsp;ID2&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to fill in the missing value of ID2 with the value in ID1. In data set programming I would usually say IF ID2 = '&amp;nbsp; &amp;nbsp; ' then ID2 = ID1.&amp;nbsp; This will give me the value of 4 for the ID2 missing record.&amp;nbsp; This is easy in the SAS Datastep, but does anyone know how to accomplish the same result using PROC SQL?&amp;nbsp; Please note, I will have to do this over many records and we will be using SQL more often, but at this point if I can have the PROC SQL code that would help me greatly.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried using CASE WHEN but it doesn't seem to look across more than one variable.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Oct 2024 22:31:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-Proc-SQL-to-assign-values-from-one-variable-to/m-p/949673#M371455</guid>
      <dc:creator>mtakayesu1</dc:creator>
      <dc:date>2024-10-31T22:31:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to use Proc SQL to assign values from one variable to another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-Proc-SQL-to-assign-values-from-one-variable-to/m-p/949674#M371456</link>
      <description>&lt;P&gt;Yes, CASE will work exactly the same as your IF statement for this case.&lt;/P&gt;
&lt;P&gt;So if in a data step you did:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  if missing(id2) then id2=id1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then in SQL you could do:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
  select id1,case when (missing(id2)) then id1 else id2 end as id2
  from have
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But in both of them you would normally just use the COALESCE() function instead for this.&amp;nbsp; (If the ID variables are character then in a data step you would need to use COALSECEC(), but in SQL you can just use COALESCE() for either numeric or character values).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  id2 = coalesce(id2,id1);
run;
proc sql;
create table want as
  select id1,coalesce(id2,id1) as id2
  from have
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 Oct 2024 22:43:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-Proc-SQL-to-assign-values-from-one-variable-to/m-p/949674#M371456</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-10-31T22:43:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to use Proc SQL to assign values from one variable to another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-Proc-SQL-to-assign-values-from-one-variable-to/m-p/949676#M371458</link>
      <description>Thank you very much!</description>
      <pubDate>Thu, 31 Oct 2024 23:04:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-Proc-SQL-to-assign-values-from-one-variable-to/m-p/949676#M371458</guid>
      <dc:creator>mtakayesu1</dc:creator>
      <dc:date>2024-10-31T23:04:43Z</dc:date>
    </item>
  </channel>
</rss>

