<?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 SELECT Statement / Assigning Values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SELECT-Statement-Assigning-Values/m-p/232595#M42401</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was wondering if there were some remedy for my issue. I have a data set, and I am creating new variables via an assignment statement based on the values of another variable from a select statement. However, when I do so, I'm left with missing variables in all of the other categories, and I'd like them to be assigned a value of zero instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA HAVE;&lt;BR /&gt;INPUT RACE1;&lt;BR /&gt;DATALINES;&lt;BR /&gt;1&lt;BR /&gt;2&lt;BR /&gt;3&lt;BR /&gt;4&lt;BR /&gt;5&lt;BR /&gt;6&lt;BR /&gt;7&lt;BR /&gt;8&lt;BR /&gt;9&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA HAVE2;&lt;BR /&gt;SET HAVE;&lt;BR /&gt;SELECT (RACE1);&lt;BR /&gt;&amp;nbsp;WHEN (1) WHITE=1;&lt;BR /&gt;&amp;nbsp;WHEN (2) BLACK=1;&lt;BR /&gt;&amp;nbsp;WHEN (3,4,5) NATIVE=1;&lt;BR /&gt;&amp;nbsp;WHEN (6,7) ASIAN=1;&lt;BR /&gt;&amp;nbsp;WHEN (8,9) OTHER=1;&lt;BR /&gt;END;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there any way to accomplish this with a select statement? I'm trying to avoid a complicated series of IF-THE/ELSE statements, and I've also done it with an ARRAY and DO loop combo, but I'm curious if there's just some simple I could use as part of this code to assign zeroes to all my missing values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;</description>
    <pubDate>Sat, 31 Oct 2015 22:27:36 GMT</pubDate>
    <dc:creator>KyleM_Corrie</dc:creator>
    <dc:date>2015-10-31T22:27:36Z</dc:date>
    <item>
      <title>SELECT Statement / Assigning Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SELECT-Statement-Assigning-Values/m-p/232595#M42401</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was wondering if there were some remedy for my issue. I have a data set, and I am creating new variables via an assignment statement based on the values of another variable from a select statement. However, when I do so, I'm left with missing variables in all of the other categories, and I'd like them to be assigned a value of zero instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA HAVE;&lt;BR /&gt;INPUT RACE1;&lt;BR /&gt;DATALINES;&lt;BR /&gt;1&lt;BR /&gt;2&lt;BR /&gt;3&lt;BR /&gt;4&lt;BR /&gt;5&lt;BR /&gt;6&lt;BR /&gt;7&lt;BR /&gt;8&lt;BR /&gt;9&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA HAVE2;&lt;BR /&gt;SET HAVE;&lt;BR /&gt;SELECT (RACE1);&lt;BR /&gt;&amp;nbsp;WHEN (1) WHITE=1;&lt;BR /&gt;&amp;nbsp;WHEN (2) BLACK=1;&lt;BR /&gt;&amp;nbsp;WHEN (3,4,5) NATIVE=1;&lt;BR /&gt;&amp;nbsp;WHEN (6,7) ASIAN=1;&lt;BR /&gt;&amp;nbsp;WHEN (8,9) OTHER=1;&lt;BR /&gt;END;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there any way to accomplish this with a select statement? I'm trying to avoid a complicated series of IF-THE/ELSE statements, and I've also done it with an ARRAY and DO loop combo, but I'm curious if there's just some simple I could use as part of this code to assign zeroes to all my missing values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Sat, 31 Oct 2015 22:27:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SELECT-Statement-Assigning-Values/m-p/232595#M42401</guid>
      <dc:creator>KyleM_Corrie</dc:creator>
      <dc:date>2015-10-31T22:27:36Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT Statement / Assigning Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SELECT-Statement-Assigning-Values/m-p/232600#M42404</link>
      <description>&lt;P&gt;COALESCE function using SQL as shown below will take care of your issue...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA HAVE;
INPUT RACE1;
DATALINES;
1
2
3
4
5
6
7
8
9
;
RUN;
 
DATA HAVE2;
SET HAVE;
SELECT (RACE1);
 WHEN (1) WHITE=1;
 WHEN (2) BLACK=1;
 WHEN (3,4,5) NATIVE=1;
 WHEN (6,7) ASIAN=1;
 WHEN (8,9) OTHER=1;
END;
RUN;
&lt;FONT color="#0000FF"&gt;proc sql; &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;     create table have2 as select race1,
     coalesce(white,0),coalesce(black,0),coalesce(native,0),coalesce(asian,0),coalesce(other,0)
     from have2;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;quit;&lt;/FONT&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Good Luck...!!!&lt;/P&gt;</description>
      <pubDate>Sun, 01 Nov 2015 00:23:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SELECT-Statement-Assigning-Values/m-p/232600#M42404</guid>
      <dc:creator>kannand</dc:creator>
      <dc:date>2015-11-01T00:23:26Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT Statement / Assigning Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SELECT-Statement-Assigning-Values/m-p/232602#M42405</link>
      <description>&lt;P&gt;An easy way to do the same:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc stdize data=have2 out=want reponly missing=0;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It will replace missing values with 0 for all numerical variables in the dataset have2. If you want specific variables for this treatment, just add var statement&amp;nbsp;in above syntax&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc stdize data=have2 out=want reponly missing=0;&lt;/P&gt;
&lt;P&gt;var white black; /* this will repace missing with 0 in white and black variables only */&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 01 Nov 2015 01:12:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SELECT-Statement-Assigning-Values/m-p/232602#M42405</guid>
      <dc:creator>stat_sas</dc:creator>
      <dc:date>2015-11-01T01:12:44Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT Statement / Assigning Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SELECT-Statement-Assigning-Values/m-p/232603#M42406</link>
      <description>&lt;P&gt;Thanks for the suggestions, guys.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think the easiest way was to add a system option.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;OPTIONS MISSING=0;&lt;/P&gt;</description>
      <pubDate>Sun, 01 Nov 2015 01:38:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SELECT-Statement-Assigning-Values/m-p/232603#M42406</guid>
      <dc:creator>KyleM_Corrie</dc:creator>
      <dc:date>2015-11-01T01:38:21Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT Statement / Assigning Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SELECT-Statement-Assigning-Values/m-p/232604#M42407</link>
      <description>&lt;P&gt;It might be worthwhile to note that the OPTIONS MISSING= just changes the way data is displayed but does not internally change the value.... please refer to&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.sascommunity.org/wiki/Tips:Convert_MISSING_to_0" target="_blank"&gt;http://www.sascommunity.org/wiki/Tips:Convert_MISSING_to_0&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 01 Nov 2015 01:44:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SELECT-Statement-Assigning-Values/m-p/232604#M42407</guid>
      <dc:creator>kannand</dc:creator>
      <dc:date>2015-11-01T01:44:13Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT Statement / Assigning Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SELECT-Statement-Assigning-Values/m-p/232621#M42410</link>
      <description>&lt;P&gt;If you actually want your variables to take values 0 or 1, I think the simplest way is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA HAVE2;
SET HAVE;
WHITE = RACE1 IN (1);
BLACK = RACE1 IN (2);
NATIVE = RACE1 IN (3, 4, 5);
ASIAN = RACE1 IN (6, 7);
OTHER = RACE1 IN (8, 9);
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 01 Nov 2015 04:24:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SELECT-Statement-Assigning-Values/m-p/232621#M42410</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2015-11-01T04:24:43Z</dc:date>
    </item>
    <item>
      <title>Re: SELECT Statement / Assigning Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SELECT-Statement-Assigning-Values/m-p/232638#M42413</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
   value race 1='White' 2='Black' 3,4,5='Natice' 6,7='Asian' 8,9='Other';
   run;
DATA HAVE;
   do race1=1 to 9;
      output;
      end;
   RUN;
proc transreg cprefix=0;;
   model class(race1/zero=none);
   format race1 race.;
   output design out=dummies(drop=_: int:);
   run;
proc print;
   run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/694iE49E48792C4113C7/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="Capture.PNG" title="Capture.PNG" /&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 01 Nov 2015 13:09:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SELECT-Statement-Assigning-Values/m-p/232638#M42413</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2015-11-01T13:09:44Z</dc:date>
    </item>
  </channel>
</rss>

