<?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: How to replace a blank value with -1 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-a-blank-value-with-1/m-p/804193#M316653</link>
    <description>&lt;P&gt;When you intend to process many variables in exactly the same way, the right tool for the job is an array.&amp;nbsp; For example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set example;
array items {*} item: ;
do _n_=1 to dim(items)
   if items{_n_} in (' ', '.') then items{_n_} = ' ';
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 25 Mar 2022 22:18:53 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2022-03-25T22:18:53Z</dc:date>
    <item>
      <title>How to replace a blank value with -1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-a-blank-value-with-1/m-p/804158#M316641</link>
      <description>&lt;P&gt;Hello, fellow SAS users,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a large dataset with many blank values. I need to replace the blank values with -1. I use the following code but it only changes one variable at a time. I am wondering if someone could help me out with this. Thank you so much!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data example;&lt;/P&gt;&lt;P&gt;input ID&amp;nbsp; Item105 $ Item124 $&amp;nbsp; Item192 $ Item020 $ Item 005 $ Item 041 $ Item225 $ Item308 $;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;001 A . B 1 . 0 C A&lt;/P&gt;&lt;P&gt;002 B D A 0 0 . . C&lt;/P&gt;&lt;P&gt;003 . A C . . 1 B .&lt;/P&gt;&lt;P&gt;004 C C . . 1 0 A C&lt;/P&gt;&lt;P&gt;005 B . D 0 0 1 . .&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;input ID&amp;nbsp; Item105 $ Item124 $&amp;nbsp; Item192 $ Item020 $ Item 005 $ Item 041 $ Item225 $ Item308 $;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;001 A -1 B 1 -1 0 C A&lt;/P&gt;&lt;P&gt;002 B D A 0 0 -1 -1 C&lt;/P&gt;&lt;P&gt;003 -1 A C -1 -1 1 B -1&lt;/P&gt;&lt;P&gt;004 C C -1 -1 1 0 A C&lt;/P&gt;&lt;P&gt;005 B -1 D 0 0 1 -1 -1&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This code works but I have over 1000 variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want; set data example;&lt;/P&gt;&lt;P&gt;if Item105 in (' ',&amp;nbsp; '.') then Item105='-1';&lt;/P&gt;&lt;P&gt;if Item124 in (' ',&amp;nbsp; '.') then Item105='-1';&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>Fri, 25 Mar 2022 18:27:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replace-a-blank-value-with-1/m-p/804158#M316641</guid>
      <dc:creator>lapetitemaman</dc:creator>
      <dc:date>2022-03-25T18:27:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace a blank value with -1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-a-blank-value-with-1/m-p/804159#M316642</link>
      <description>data want; set data example;&lt;BR /&gt;if Item105 in (' ', '.') then Item105='-1';&lt;BR /&gt;if Item124 in (' ', '.') then Item124='-1';&lt;BR /&gt;&lt;BR /&gt;run;</description>
      <pubDate>Fri, 25 Mar 2022 18:27:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replace-a-blank-value-with-1/m-p/804159#M316642</guid>
      <dc:creator>lapetitemaman</dc:creator>
      <dc:date>2022-03-25T18:27:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace a blank value with -1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-a-blank-value-with-1/m-p/804193#M316653</link>
      <description>&lt;P&gt;When you intend to process many variables in exactly the same way, the right tool for the job is an array.&amp;nbsp; For example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set example;
array items {*} item: ;
do _n_=1 to dim(items)
   if items{_n_} in (' ', '.') then items{_n_} = ' ';
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 Mar 2022 22:18:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replace-a-blank-value-with-1/m-p/804193#M316653</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2022-03-25T22:18:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace a blank value with -1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-a-blank-value-with-1/m-p/804199#M316658</link>
      <description>&lt;P&gt;What is special about the value -1 in your later steps?&lt;/P&gt;
&lt;P&gt;It is also a bit suspect that all of your of your variables are character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your data step as posted does not run because you have spaces between "item" and the number for a couple variables on the Input statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I might be that a format is the simplest to display that value without changing the original values though likely not if some of your values are much longer than a couple characters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc format;
value $dashone
' ' = '-1'
;
run;

data example;
input ID  Item105 $ Item124 $  Item192 $ Item020 $ Item005 $ Item041 $ Item225 $ Item308 $;
datalines;
001 A . B 1 . 0 C A
002 B D A 0 0 . . C
003 . A C . . 1 B .
004 C C . . 1 0 A C
005 B . D 0 0 1 . .
;

proc print data=example;
   format _character_ $dashone.;
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 Mar 2022 23:42:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replace-a-blank-value-with-1/m-p/804199#M316658</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-03-25T23:42:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace a blank value with -1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-a-blank-value-with-1/m-p/804244#M316694</link>
      <description>What is the point of doing this?&lt;BR /&gt;&lt;BR /&gt;What can you do with '-1' that you can't do with '.'?</description>
      <pubDate>Sat, 26 Mar 2022 09:40:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replace-a-blank-value-with-1/m-p/804244#M316694</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-03-26T09:40:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace a blank value with -1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-a-blank-value-with-1/m-p/804320#M316727</link>
      <description>&lt;P&gt;If this is about actually changing the values from missing to -1 then using an array as already shown is likely what you need to do. But as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;writes: What is the point of doing this? What does -1 allow you to do that a missing doesn't.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it's simply about reporting and "looking" at the data then consider to use a format instead that you then apply to all the variables.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 27 Mar 2022 01:10:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replace-a-blank-value-with-1/m-p/804320#M316727</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-03-27T01:10:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace a blank value with -1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-a-blank-value-with-1/m-p/804511#M316826</link>
      <description>Thank you! This worked. I have tried to use array but couldn't get my code to work properly. Thanks again!</description>
      <pubDate>Mon, 28 Mar 2022 14:01:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replace-a-blank-value-with-1/m-p/804511#M316826</guid>
      <dc:creator>lapetitemaman</dc:creator>
      <dc:date>2022-03-28T14:01:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace a blank value with -1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-a-blank-value-with-1/m-p/804512#M316827</link>
      <description>These are all character variables. I am not sure why there are spaces. I am new to this forum and still learning how to post questions.</description>
      <pubDate>Mon, 28 Mar 2022 14:03:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replace-a-blank-value-with-1/m-p/804512#M316827</guid>
      <dc:creator>lapetitemaman</dc:creator>
      <dc:date>2022-03-28T14:03:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace a blank value with -1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-a-blank-value-with-1/m-p/804513#M316828</link>
      <description>I had to set up a dataset this way in order to properly run in another program.</description>
      <pubDate>Mon, 28 Mar 2022 14:03:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replace-a-blank-value-with-1/m-p/804513#M316828</guid>
      <dc:creator>lapetitemaman</dc:creator>
      <dc:date>2022-03-28T14:03:47Z</dc:date>
    </item>
  </channel>
</rss>

