<?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 update data in existing variables by using proc sql? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/how-to-update-data-in-existing-variables-by-using-proc-sql/m-p/331055#M62672</link>
    <description>&lt;P&gt;Hello:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to use PROC SQL according to the following data steps. &amp;nbsp;I am thinking of using "update' statement and "Case...end". &amp;nbsp;However, I don't know how to work in the multiple variables.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; dataout.recat1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set dataout.test;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if age in (&lt;STRONG&gt;1&lt;/STRONG&gt;,&lt;STRONG&gt;2&lt;/STRONG&gt;,&lt;STRONG&gt;3&lt;/STRONG&gt;,&lt;STRONG&gt;4&lt;/STRONG&gt;,&lt;STRONG&gt;5&lt;/STRONG&gt;) then age=&lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if marital in (&lt;STRONG&gt;2&lt;/STRONG&gt;, &lt;STRONG&gt;4&lt;/STRONG&gt;) then marital=&lt;STRONG&gt;2&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if income in (&lt;STRONG&gt;1&lt;/STRONG&gt;,&lt;STRONG&gt;2&lt;/STRONG&gt;,&lt;STRONG&gt;3&lt;/STRONG&gt;) then income=&lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 09 Feb 2017 02:38:33 GMT</pubDate>
    <dc:creator>ybz12003</dc:creator>
    <dc:date>2017-02-09T02:38:33Z</dc:date>
    <item>
      <title>how to update data in existing variables by using proc sql?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-update-data-in-existing-variables-by-using-proc-sql/m-p/331055#M62672</link>
      <description>&lt;P&gt;Hello:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to use PROC SQL according to the following data steps. &amp;nbsp;I am thinking of using "update' statement and "Case...end". &amp;nbsp;However, I don't know how to work in the multiple variables.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; dataout.recat1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set dataout.test;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if age in (&lt;STRONG&gt;1&lt;/STRONG&gt;,&lt;STRONG&gt;2&lt;/STRONG&gt;,&lt;STRONG&gt;3&lt;/STRONG&gt;,&lt;STRONG&gt;4&lt;/STRONG&gt;,&lt;STRONG&gt;5&lt;/STRONG&gt;) then age=&lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if marital in (&lt;STRONG&gt;2&lt;/STRONG&gt;, &lt;STRONG&gt;4&lt;/STRONG&gt;) then marital=&lt;STRONG&gt;2&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if income in (&lt;STRONG&gt;1&lt;/STRONG&gt;,&lt;STRONG&gt;2&lt;/STRONG&gt;,&lt;STRONG&gt;3&lt;/STRONG&gt;) then income=&lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Feb 2017 02:38:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-update-data-in-existing-variables-by-using-proc-sql/m-p/331055#M62672</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2017-02-09T02:38:33Z</dc:date>
    </item>
    <item>
      <title>Re: how to update data in existing variables by using proc sql?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-update-data-in-existing-variables-by-using-proc-sql/m-p/331058#M62673</link>
      <description>&lt;P&gt;This is another difficult problem to solve accurately without having the source data available to test it. However this code&amp;nbsp;&lt;EM&gt;wll&lt;/EM&gt; work. Whether it's what you want is another thing:&lt;/P&gt;
&lt;PRE&gt;proc sql;&lt;BR /&gt;create table dataout.recat1 as&lt;BR /&gt; select ifn(age in(1, 2, 3, 4, 5), 1, .) as age,&lt;BR /&gt;        ifn(marital in(2, 4), 2, .) as marital,&lt;BR /&gt;        ifn(income in(1, 2, 3), 1, .) as income&lt;BR /&gt;   from dataout.test;&lt;BR /&gt;quit;&lt;/PRE&gt;
&lt;P&gt;The first&amp;nbsp;&lt;EM&gt;ifn&lt;/EM&gt; function tests age to see if it's 1 - 5; if it is, age is reset to 1, but if not it's set to missing. The same pattern is in the next two lines. I use&amp;nbsp;&lt;EM&gt;ifn&lt;/EM&gt;&lt;EM&gt;&amp;nbsp;or&lt;/EM&gt;&amp;nbsp;ifc if there are only going to be two possibilities; if there are more I use &lt;EM&gt;case/when/else&lt;/EM&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want other variables in the output dataset, you need to specify them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that you would only use update if you were replacing the dataset; in your datastep code you specify a&amp;nbsp;&lt;EM&gt;different&lt;/EM&gt; dataset.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Feb 2017 03:31:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-update-data-in-existing-variables-by-using-proc-sql/m-p/331058#M62673</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2017-02-09T03:31:40Z</dc:date>
    </item>
    <item>
      <title>Re: how to update data in existing variables by using proc sql?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-update-data-in-existing-variables-by-using-proc-sql/m-p/331062#M62674</link>
      <description>&lt;P&gt;I don't like set extra missing "." for 1-5 cause there are missing "." in original&amp;nbsp;data. &amp;nbsp;It will cause the confusion.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Feb 2017 04:00:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-update-data-in-existing-variables-by-using-proc-sql/m-p/331062#M62674</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2017-02-09T04:00:00Z</dc:date>
    </item>
    <item>
      <title>Re: how to update data in existing variables by using proc sql?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-update-data-in-existing-variables-by-using-proc-sql/m-p/331064#M62675</link>
      <description>That's why I pointed out the lack of data, and specification. Can you attach your source data and how you want the output to look? It's really hard otherwise. &lt;BR /&gt;</description>
      <pubDate>Thu, 09 Feb 2017 04:10:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-update-data-in-existing-variables-by-using-proc-sql/m-p/331064#M62675</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2017-02-09T04:10:25Z</dc:date>
    </item>
  </channel>
</rss>

