<?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: Can I use Case when expression with a single condition and no new variable in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Can-I-use-Case-when-expression-with-a-single-condition-and-no/m-p/561439#M10595</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If all you want to do here is to update the "Car_model" variable by changing missing values to 'Unspecified', you could consider using a format, such as:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;**Make a format**;
proc format;
  value $model_miss (default = 50)
  ' ' = 'Unspecified'
  ;
run;


**Apply the format to car_model and save as a new dataset**;
data car_history2;
  set car_history;
  car_model = put(car_model, $model_miss.);
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 24 May 2019 15:21:17 GMT</pubDate>
    <dc:creator>aaronh</dc:creator>
    <dc:date>2019-05-24T15:21:17Z</dc:date>
    <item>
      <title>Can I use Case when expression with a single condition and no new variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Can-I-use-Case-when-expression-with-a-single-condition-and-no/m-p/561405#M10585</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am wondering if it is possible to use case when expression in Proc SQL to replace missing values of a variable based on a single condition without creating a new variable.&lt;/P&gt;&lt;P&gt;I know that I can work around this by creating a new variable and then dropping it later if needed but I wanted to find out if it is possible without creating a new variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For e.g. If I have to replace missing values of Car_Model variable to Unspecified&amp;nbsp; from Car_History dataset, can I do something like this ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Proc Sql;&lt;/P&gt;&lt;P&gt;create table New_Cars as&lt;/P&gt;&lt;P&gt;select distinct *,&lt;/P&gt;&lt;P&gt;case when Car_Model is missing then 'Unspecified'&amp;nbsp;&lt;/P&gt;&lt;P&gt;end&lt;/P&gt;&lt;P&gt;from Car_History;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 May 2019 14:16:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Can-I-use-Case-when-expression-with-a-single-condition-and-no/m-p/561405#M10585</guid>
      <dc:creator>VarunD</dc:creator>
      <dc:date>2019-05-24T14:16:17Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use Case when expression with a single condition and no new variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Can-I-use-Case-when-expression-with-a-single-condition-and-no/m-p/561407#M10587</link>
      <description>&lt;P&gt;Does the following help:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* set all names beginning with 'J' to missing */
data have;
   set sashelp.class;
   
   if name =: 'J' then
      call missing(name);
run;

/* update missing values */
proc sql;
   update
      have
   set
      name = 'N/A'
   where
      missing(name)
   ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Fri, 24 May 2019 14:24:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Can-I-use-Case-when-expression-with-a-single-condition-and-no/m-p/561407#M10587</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2019-05-24T14:24:44Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use Case when expression with a single condition and no new variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Can-I-use-Case-when-expression-with-a-single-condition-and-no/m-p/561408#M10588</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/194984"&gt;@VarunD&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For e.g. If I have to replace missing values of Car_Model variable to Unspecified&amp;nbsp; from Car_History dataset, can I do something like this ?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc Sql;&lt;/P&gt;
&lt;P&gt;create table New_Cars as&lt;/P&gt;
&lt;P&gt;select distinct *,&lt;/P&gt;
&lt;P&gt;case when Car_Model is missing then 'Unspecified'&amp;nbsp;&lt;/P&gt;
&lt;P&gt;end&lt;/P&gt;
&lt;P&gt;from Car_History;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Looks like it should run, but maybe you want this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case when missing(Car_Model) then 'Unspecified'&amp;nbsp;else car_model end as car_model&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 May 2019 14:25:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Can-I-use-Case-when-expression-with-a-single-condition-and-no/m-p/561408#M10588</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-05-24T14:25:19Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use Case when expression with a single condition and no new variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Can-I-use-Case-when-expression-with-a-single-condition-and-no/m-p/561432#M10591</link>
      <description>&lt;P&gt;Code runs but the missing values are still missing.&lt;/P&gt;&lt;P&gt;I get a warning that "Variable Car_Model already exists on file WORK.Car_History"&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 May 2019 15:13:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Can-I-use-Case-when-expression-with-a-single-condition-and-no/m-p/561432#M10591</guid>
      <dc:creator>VarunD</dc:creator>
      <dc:date>2019-05-24T15:13:53Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use Case when expression with a single condition and no new variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Can-I-use-Case-when-expression-with-a-single-condition-and-no/m-p/561433#M10592</link>
      <description>Thanks for your help. I appreciate it. It sound like it should work buy I wanted to find out if case when expression can be used in this case.</description>
      <pubDate>Fri, 24 May 2019 15:15:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Can-I-use-Case-when-expression-with-a-single-condition-and-no/m-p/561433#M10592</guid>
      <dc:creator>VarunD</dc:creator>
      <dc:date>2019-05-24T15:15:45Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use Case when expression with a single condition and no new variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Can-I-use-Case-when-expression-with-a-single-condition-and-no/m-p/561436#M10593</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case when missing(Car_Model) then 'Unspecified' else car_model end as car_model1&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If that doesn't fix the problem, then you need to provide a portion of your actual data set&amp;nbsp;&lt;STRONG&gt;following these instructions:&amp;nbsp;&lt;/STRONG&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 24 May 2019 15:21:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Can-I-use-Case-when-expression-with-a-single-condition-and-no/m-p/561436#M10593</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-05-24T15:21:09Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use Case when expression with a single condition and no new variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Can-I-use-Case-when-expression-with-a-single-condition-and-no/m-p/561437#M10594</link>
      <description>&lt;P&gt;You can, but maybe you want the COALESCE() function instead? It goes through a list of variables and picks the first non-missing, but you can also include a string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select distinct *, coalesce(car_model, 'Unspecified') as Car_Model
from car_history;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/194984"&gt;@VarunD&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am wondering if it is possible to use case when expression in Proc SQL to replace missing values of a variable based on a single condition without creating a new variable.&lt;/P&gt;
&lt;P&gt;I know that I can work around this by creating a new variable and then dropping it later if needed but I wanted to find out if it is possible without creating a new variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For e.g. If I have to replace missing values of Car_Model variable to Unspecified&amp;nbsp; from Car_History dataset, can I do something like this ?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc Sql;&lt;/P&gt;
&lt;P&gt;create table New_Cars as&lt;/P&gt;
&lt;P&gt;select distinct *,&lt;/P&gt;
&lt;P&gt;case when Car_Model is missing then 'Unspecified'&amp;nbsp;&lt;/P&gt;
&lt;P&gt;end&lt;/P&gt;
&lt;P&gt;from Car_History;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 May 2019 15:20:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Can-I-use-Case-when-expression-with-a-single-condition-and-no/m-p/561437#M10594</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-05-24T15:20:12Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use Case when expression with a single condition and no new variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Can-I-use-Case-when-expression-with-a-single-condition-and-no/m-p/561439#M10595</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If all you want to do here is to update the "Car_model" variable by changing missing values to 'Unspecified', you could consider using a format, such as:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;**Make a format**;
proc format;
  value $model_miss (default = 50)
  ' ' = 'Unspecified'
  ;
run;


**Apply the format to car_model and save as a new dataset**;
data car_history2;
  set car_history;
  car_model = put(car_model, $model_miss.);
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 May 2019 15:21:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Can-I-use-Case-when-expression-with-a-single-condition-and-no/m-p/561439#M10595</guid>
      <dc:creator>aaronh</dc:creator>
      <dc:date>2019-05-24T15:21:17Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use Case when expression with a single condition and no new variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Can-I-use-Case-when-expression-with-a-single-condition-and-no/m-p/561442#M10596</link>
      <description>But this will create a new variable car_model1, isn't it ?</description>
      <pubDate>Fri, 24 May 2019 15:37:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Can-I-use-Case-when-expression-with-a-single-condition-and-no/m-p/561442#M10596</guid>
      <dc:creator>VarunD</dc:creator>
      <dc:date>2019-05-24T15:37:03Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use Case when expression with a single condition and no new variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Can-I-use-Case-when-expression-with-a-single-condition-and-no/m-p/561443#M10597</link>
      <description>&lt;P&gt;Yes, it will.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you don't want that, then you have to replace&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select distinct *,&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;with a list of variables that does not include car_model (where I assume that you have variables named VARIABLE1, VARIABLE2, etc.) and the car_model is specifically left out of this list.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select distinct variable1,variable2,&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 May 2019 15:39:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Can-I-use-Case-when-expression-with-a-single-condition-and-no/m-p/561443#M10597</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-05-24T15:39:39Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use Case when expression with a single condition and no new variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Can-I-use-Case-when-expression-with-a-single-condition-and-no/m-p/561444#M10598</link>
      <description>&lt;P&gt;I think the reason you're getting the 'already exists' message is because you are selecting all columns to start with using '*'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Instead, try listing the columns individually and in place of '&lt;SPAN&gt;Car_Model&lt;/SPAN&gt;' use the logic suggested by others so it&lt;SPAN&gt;&amp;nbsp;won't try to create a duplicate.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Amir.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 24 May 2019 15:42:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Can-I-use-Case-when-expression-with-a-single-condition-and-no/m-p/561444#M10598</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2019-05-24T15:42:39Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use Case when expression with a single condition and no new variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Can-I-use-Case-when-expression-with-a-single-condition-and-no/m-p/561453#M10599</link>
      <description>Thanks a lot. That was the problem. Great catch.</description>
      <pubDate>Fri, 24 May 2019 15:57:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Can-I-use-Case-when-expression-with-a-single-condition-and-no/m-p/561453#M10599</guid>
      <dc:creator>VarunD</dc:creator>
      <dc:date>2019-05-24T15:57:42Z</dc:date>
    </item>
    <item>
      <title>Re: Can I use Case when expression with a single condition and no new variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Can-I-use-Case-when-expression-with-a-single-condition-and-no/m-p/561454#M10600</link>
      <description>Very Interesting ! Thanks a lot for your help.</description>
      <pubDate>Fri, 24 May 2019 15:59:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Can-I-use-Case-when-expression-with-a-single-condition-and-no/m-p/561454#M10600</guid>
      <dc:creator>VarunD</dc:creator>
      <dc:date>2019-05-24T15:59:09Z</dc:date>
    </item>
  </channel>
</rss>

