<?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 Replacing Data Entries in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Replacing-Data-Entries/m-p/100230#M28144</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm new to SAS and after doing a lot of searching, I can't seem to get some simple data operations to work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Given a dataset, I want to replace certain data entries systematically. My document contains several unwanted entries with the string "DQ" and I want to replace them in the data step with missing values ".". The problem is, I get errors and I suspect it has to do because the "DQ" entries are given for both numerical and categorical variables. I have tried three different approaches, and all of them have yielded errors that my data is invalid still. Note: when I used the 'replace all' function in notepad and ran the data, I had no "invalid data" problems.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To show my approaches, let "categorical" and "numerical" be my variables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Approach #1:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;numerical = .;&lt;/P&gt;&lt;P&gt;replace all var{numerical} where(numerical = "DQ);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;categorical = ".";&lt;/P&gt;&lt;P&gt;replace all var{categorical} where(categorical = "DQ");&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Approach #2:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if numerical = "DQ" then numerical = .;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if categorical = "DQ" then categorical = ".";&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Approach #3:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;numerical = tranwrd(numerical, "DQ", .);&lt;/P&gt;&lt;P&gt;categorical=tranwrd(categorical, "DQ", ".");&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there something fundamentally wrong with my approach? Even though I distinguish between "." and . without quotations - I have not been able to successfully run the data. I run SAS remotely, so I cannot view the data from within the program; the log simply informs me of the errors. Thanks in advance.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 08 Jun 2013 00:25:35 GMT</pubDate>
    <dc:creator>disguy</dc:creator>
    <dc:date>2013-06-08T00:25:35Z</dc:date>
    <item>
      <title>Replacing Data Entries</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Replacing-Data-Entries/m-p/100230#M28144</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm new to SAS and after doing a lot of searching, I can't seem to get some simple data operations to work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Given a dataset, I want to replace certain data entries systematically. My document contains several unwanted entries with the string "DQ" and I want to replace them in the data step with missing values ".". The problem is, I get errors and I suspect it has to do because the "DQ" entries are given for both numerical and categorical variables. I have tried three different approaches, and all of them have yielded errors that my data is invalid still. Note: when I used the 'replace all' function in notepad and ran the data, I had no "invalid data" problems.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To show my approaches, let "categorical" and "numerical" be my variables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Approach #1:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;numerical = .;&lt;/P&gt;&lt;P&gt;replace all var{numerical} where(numerical = "DQ);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;categorical = ".";&lt;/P&gt;&lt;P&gt;replace all var{categorical} where(categorical = "DQ");&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Approach #2:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if numerical = "DQ" then numerical = .;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if categorical = "DQ" then categorical = ".";&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Approach #3:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;numerical = tranwrd(numerical, "DQ", .);&lt;/P&gt;&lt;P&gt;categorical=tranwrd(categorical, "DQ", ".");&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there something fundamentally wrong with my approach? Even though I distinguish between "." and . without quotations - I have not been able to successfully run the data. I run SAS remotely, so I cannot view the data from within the program; the log simply informs me of the errors. Thanks in advance.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 08 Jun 2013 00:25:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Replacing-Data-Entries/m-p/100230#M28144</guid>
      <dc:creator>disguy</dc:creator>
      <dc:date>2013-06-08T00:25:35Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing Data Entries</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Replacing-Data-Entries/m-p/100231#M28145</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Approach 2 is almost it. Try this way:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if LEFT(numerical) = "DQ" then numerical = "";&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if LEFT(categorical) = "DQ" then categorical = "";&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 08 Jun 2013 01:28:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Replacing-Data-Entries/m-p/100231#M28145</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2013-06-08T01:28:58Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing Data Entries</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Replacing-Data-Entries/m-p/100232#M28146</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the reply. Unfortunately, it did not work (same issues as before).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When the log lists the data values for each variable, it shows that the values have been changed to "." - as desired (and also as with the methods I listed in my original post).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, for multiple lines the log writes "NOTE: Invalid date for numerical in line XXX XX-XX". It seems to be doing this only for the numerical variable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;EDIT: And if I'm not mistaken, it seems to only be outputting this error for observations where both the numerical and categorical variables have the entry "DQ".&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 08 Jun 2013 01:48:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Replacing-Data-Entries/m-p/100232#M28146</guid>
      <dc:creator>disguy</dc:creator>
      <dc:date>2013-06-08T01:48:31Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing Data Entries</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Replacing-Data-Entries/m-p/100233#M28147</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If numerical really is a numerical variable and it prints as "DQ" then it must have an associated format that represents some numerical values as "DQ". You could try&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;if left(vvalue(numerical))="DQ" then call missing(numerical);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If that doesn't work, please post the result of :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc contents data=&lt;EM&gt;yourDatasetName&lt;/EM&gt;; run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: SAS Monospace Bold;"&gt;PG&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 08 Jun 2013 02:42:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Replacing-Data-Entries/m-p/100233#M28147</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2013-06-08T02:42:05Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing Data Entries</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Replacing-Data-Entries/m-p/100234#M28148</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Unfortunately, I am using a remote version of SAS and it really limits what I can do. This being the case, I can't view the results of proc contents. However, I have uploaded the data file to pastebin: &lt;A class="active_link" href="http://http://pastebin.com/WLjLdPex"&gt;http://http://pastebin.com/WLjLdPex&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The relevant variables are "force" (the one I referred to as "numerical") and "break" (the one I referred to as "categorical"). My instructions were to replace the "DQ" values with "."&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I will post the code I used to access the data remotely:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;infile 'datafile.txt'&lt;/P&gt;&lt;P&gt;firstobs=2&lt;/P&gt;&lt;P&gt;delimiter='09'x&lt;/P&gt;&lt;P&gt;termstr=crlf;&lt;/P&gt;&lt;P&gt;input btch$ glue$ clamp$ overlap$ stick color$ user$ jig caliper force break$ quality;&lt;/P&gt;&lt;P&gt;drop btch user jig;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When attempting to replace the DQ values, I inserted the code between the drop and run statements (if that matters).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 08 Jun 2013 03:02:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Replacing-Data-Entries/m-p/100234#M28148</guid>
      <dc:creator>disguy</dc:creator>
      <dc:date>2013-06-08T03:02:38Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing Data Entries</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Replacing-Data-Entries/m-p/100235#M28149</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So if you try to read the variable FORCE (10th column in your raw data file) as a number then DQ will automatically be converted by SAS as missing value.&amp;nbsp; So you just need code to convert the 'DQ' in the character variables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;array _c _character_;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;do over _c ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; if _c='DQ' then _c='.';&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;end&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Personally I would set the character variables to blank instead of '.' .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want to avoid the error message about invalid data then you could create an informat.&amp;nbsp; You could create a character informat also.&amp;nbsp; But here is another trick that will do without informats or looping code.&amp;nbsp; The idea is to convert the data in the input buffer before reading the line into the variables.&lt;/P&gt;&lt;P&gt;Add these two lines to you current program right before the INPUT statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;input @;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;_infile_ = tranwrd(_infile_,'DQ',' .');&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SAS will read the period as missing for numeric with the conversion error messages that you are getting when it sees the DQ.&amp;nbsp; The character variables all become blank (the dot will disappear). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data test;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; infile cards firstobs=2 truncover;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; input @;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; put _infile_;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; _infile_ = tranwrd(_infile_,'DQ',' .');&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; put _infile_;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; input btch $ glue $ clamp $ overlap $ stick color $ user $ jig caliper force break $ quality;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; put (_all_) (=) /;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;cards;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;batch glue clamp overlap sticks colour user jig caliper force break quality&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;CCM2B C C M 2 B N.R 3 20 12.5 w 6&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;CCM2B C C M 2 B N.R 3 18.6 DQ DQ 0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;CCM2B C C M 2 B S.J 3 17.6 7 w 5&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;CCM2B C C M 2 B N.R 3 20 12.5 w 6&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;CCM2B C C M 2 B N.R 3 20 12.5 w 6&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;btch=CCM2B glue=C clamp=C overlap=M stick=2 color=B user=N.R jig=3 caliper=20 force=12.5 break=w quality=6&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;CCM2B C C M 2 B N.R 3 18.6 DQ DQ 0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;CCM2B C C M 2 B N.R 3 18.6&amp;nbsp; .&amp;nbsp; . 0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;btch=CCM2B glue=C clamp=C overlap=M stick=2 color=B user=N.R jig=3 caliper=18.6 force=. break=&amp;nbsp; quality=0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;CCM2B C C M 2 B S.J 3 17.6 7 w 5&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;CCM2B C C M 2 B S.J 3 17.6 7 w 5&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;btch=CCM2B glue=C clamp=C overlap=M stick=2 color=B user=S.J jig=3 caliper=17.6 force=7 break=w quality=5&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 08 Jun 2013 03:54:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Replacing-Data-Entries/m-p/100235#M28149</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-06-08T03:54:14Z</dc:date>
    </item>
  </channel>
</rss>

