<?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: coverting a character variable with number and missing values to numeric variables in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/coverting-a-character-variable-with-number-and-missing-values-to/m-p/876458#M38912</link>
    <description>&lt;P&gt;To read a CSV file with 4 columns. Three character strings with max lengths of 10,20 and 300 followed by one numeric variable that has NA instead of null strings to represent missing you could do:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
invalue na 'NA'=. other=[32.];
run;
data want;
  infile 'myfile.csv' dsd truncover firstobs=2;
  length a $10 b $20 c $300 D 8;
  input a b c d :na. ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 18 May 2023 14:01:33 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-05-18T14:01:33Z</dc:date>
    <item>
      <title>coverting a character variable with number and missing values to numeric variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/coverting-a-character-variable-with-number-and-missing-values-to/m-p/876393#M38888</link>
      <description>&lt;P&gt;Greetings everyone&lt;/P&gt;&lt;P&gt;&amp;nbsp;I have a dataset with a variable with missing values called NA. Because of this, it makes that variable a character variable, so I don't know how to make this numerical so that I can use multiple imputations to impute the missing data.&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I removed the Na and replaced it with a space; it still shows that the variable is a character variable, same with the replacing with the dot,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please, what can I do to handle this? Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 18 May 2023 08:33:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/coverting-a-character-variable-with-number-and-missing-values-to/m-p/876393#M38888</guid>
      <dc:creator>Gilles-Protais</dc:creator>
      <dc:date>2023-05-18T08:33:10Z</dc:date>
    </item>
    <item>
      <title>making a character variable with numbers and missing values(NA) to be  numeric.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/coverting-a-character-variable-with-number-and-missing-values-to/m-p/876392#M38889</link>
      <description>&lt;P&gt;Greetings everyone&lt;/P&gt;&lt;P&gt;&amp;nbsp;I have a dataset with a variable with missing values called NA. Because of this, it makes that variable a character variable, so I don't know how to make this numerical so that I can use multiple imputations to impute the missing data.&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I removed the Na and replaced it with a space; it still shows that the variable is a character variable, same with the replacing with the dot,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please, what can I do to handle this? Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 18 May 2023 08:30:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/coverting-a-character-variable-with-number-and-missing-values-to/m-p/876392#M38889</guid>
      <dc:creator>Gilles-Protais</dc:creator>
      <dc:date>2023-05-18T08:30:21Z</dc:date>
    </item>
    <item>
      <title>Re: coverting a character variable with number and missing values to numeric variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/coverting-a-character-variable-with-number-and-missing-values-to/m-p/876394#M38890</link>
      <description>&lt;P&gt;From which source do you import the data into SAS?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please do not post the same question multiple times. It only makes following the flow of the discussion harder, so I merged your posts.&lt;/P&gt;</description>
      <pubDate>Thu, 18 May 2023 09:11:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/coverting-a-character-variable-with-number-and-missing-values-to/m-p/876394#M38890</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-05-18T09:11:41Z</dc:date>
    </item>
    <item>
      <title>Re: coverting a character variable with number and missing values to numeric variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/coverting-a-character-variable-with-number-and-missing-values-to/m-p/876411#M38902</link>
      <description>&lt;P&gt;Yes, I want to import from SAS&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 May 2023 10:45:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/coverting-a-character-variable-with-number-and-missing-values-to/m-p/876411#M38902</guid>
      <dc:creator>Gilles-Protais</dc:creator>
      <dc:date>2023-05-18T10:45:38Z</dc:date>
    </item>
    <item>
      <title>Re: coverting a character variable with number and missing values to numeric variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/coverting-a-character-variable-with-number-and-missing-values-to/m-p/876412#M38903</link>
      <description>&lt;P&gt;You can not&amp;nbsp;&lt;EM&gt;import from&lt;/EM&gt; SAS. You either&amp;nbsp;&lt;EM&gt;import into&lt;/EM&gt; SAS, or&amp;nbsp;&lt;EM&gt;export from&lt;/EM&gt; SAS.&lt;/P&gt;
&lt;P&gt;If you have an external data source containing "NA" for missing values, you use an informat during the import process which reads "NA" as missing, and everything else as numbers.&lt;/P&gt;</description>
      <pubDate>Thu, 18 May 2023 10:59:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/coverting-a-character-variable-with-number-and-missing-values-to/m-p/876412#M38903</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-05-18T10:59:10Z</dc:date>
    </item>
    <item>
      <title>Re: coverting a character variable with number and missing values to numeric variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/coverting-a-character-variable-with-number-and-missing-values-to/m-p/876430#M38907</link>
      <description>Yes it is an external data source. Precisely csv&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 18 May 2023 12:47:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/coverting-a-character-variable-with-number-and-missing-values-to/m-p/876430#M38907</guid>
      <dc:creator>Gilles-Protais</dc:creator>
      <dc:date>2023-05-18T12:47:39Z</dc:date>
    </item>
    <item>
      <title>Re: coverting a character variable with number and missing values to numeric variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/coverting-a-character-variable-with-number-and-missing-values-to/m-p/876431#M38908</link>
      <description>&lt;P&gt;Thanks very much, but can i have the code format, to import the csv file as informal?,&lt;/P&gt;</description>
      <pubDate>Thu, 18 May 2023 12:49:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/coverting-a-character-variable-with-number-and-missing-values-to/m-p/876431#M38908</guid>
      <dc:creator>Gilles-Protais</dc:creator>
      <dc:date>2023-05-18T12:49:22Z</dc:date>
    </item>
    <item>
      <title>Re: coverting a character variable with number and missing values to numeric variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/coverting-a-character-variable-with-number-and-missing-values-to/m-p/876446#M38909</link>
      <description>&lt;P&gt;First, create an informat:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
invalue mynum
  'NA' = .
  other = [best20.]
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then, use it while you read the file:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
infile "path_to_your_file.csv" dlm="," dsd truncover firstobs=2;
input
  ...
  numvar :mynum.
  ...
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 May 2023 13:13:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/coverting-a-character-variable-with-number-and-missing-values-to/m-p/876446#M38909</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-05-18T13:13:15Z</dc:date>
    </item>
    <item>
      <title>Re: coverting a character variable with number and missing values to numeric variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/coverting-a-character-variable-with-number-and-missing-values-to/m-p/876454#M38910</link>
      <description>&lt;P&gt;This has been asked before.&amp;nbsp; You could try search for the previous questions and answers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In general there are two methods.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) Make version of the text file without the NA strings.&amp;nbsp; Then use what every method you want to read the converted file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename csv 'my original file.csv';
filename fixed 'my original file fixed.csv';
data _null_;
  infile csv ;
  file fixed;
  input ;
  _infile_=tranwrd(cats(',',_infile_,','),',NA,',',,');
  _infile_=substrn(_infile_,2,length(_infile_)-2);
  put _infile_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;2) Write your own data step to read the data instead of forcing SAS to GUESS how to read the file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you write your own data step you get to decide which variables are numeric and which are character.&amp;nbsp; If you don't do anything else then SAS will write a note when it sees one of those NA strings in a field being read as a numeric value, but the result will be a missing value, which is what you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Reading a CSV file is TRIVIAL with a data step.&amp;nbsp; So there is no need to resort to forcing SAS to GUESS how to read it. Just define the variables. Attach any NEEDED formats or informats.&amp;nbsp; Then read the variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  infile csv dsd truncover firstobs=2;
  length id $10 age 8 start_date 8 ;
  informat start_date yymmdd. ;
  format start_date yymmdd10.;
  input id -- start_date ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To suppress the notes about invalid values you could use the ?? modifier on the INPUT statement.&amp;nbsp; But note that will suppress ALL of the warnings about invalid values.&amp;nbsp; So values like FRED will be silently set to missing just like values like NA.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Of you could define a special INFORMAT that will convert the NA strings to missing and then use normal informat for the other values.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format ;
invalue na     'NA','na','Na' = . other = [32.] ;&lt;BR /&gt;invalue na_ymd 'NA','na','Na' = . other = [yymmdd10.] ;&lt;BR /&gt;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then use the informat in the data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  infile csv dsd truncover firstobs=2;
  length id $10 age 8 start_date 8 ;
  informat start_date na_ymd.  age na.;
  format start_date yymmdd10.;
  input id -- start_date ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 May 2023 13:38:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/coverting-a-character-variable-with-number-and-missing-values-to/m-p/876454#M38910</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-18T13:38:57Z</dc:date>
    </item>
    <item>
      <title>Re: coverting a character variable with number and missing values to numeric variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/coverting-a-character-variable-with-number-and-missing-values-to/m-p/876457#M38911</link>
      <description>&lt;P&gt;Thank you for the answer,&lt;/P&gt;&lt;P&gt;&amp;nbsp;but can easily decode what you have written, because still new to was coding.&amp;nbsp;&lt;/P&gt;&lt;P&gt;For instance if the columns of my csv file where a,b,c and c is the numeric with missing values how could I fit them into the code you given me. so sorry if am too much asking questions.&lt;/P&gt;</description>
      <pubDate>Thu, 18 May 2023 13:44:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/coverting-a-character-variable-with-number-and-missing-values-to/m-p/876457#M38911</guid>
      <dc:creator>Gilles-Protais</dc:creator>
      <dc:date>2023-05-18T13:44:19Z</dc:date>
    </item>
    <item>
      <title>Re: coverting a character variable with number and missing values to numeric variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/coverting-a-character-variable-with-number-and-missing-values-to/m-p/876458#M38912</link>
      <description>&lt;P&gt;To read a CSV file with 4 columns. Three character strings with max lengths of 10,20 and 300 followed by one numeric variable that has NA instead of null strings to represent missing you could do:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
invalue na 'NA'=. other=[32.];
run;
data want;
  infile 'myfile.csv' dsd truncover firstobs=2;
  length a $10 b $20 c $300 D 8;
  input a b c d :na. ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 May 2023 14:01:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/coverting-a-character-variable-with-number-and-missing-values-to/m-p/876458#M38912</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-18T14:01:33Z</dc:date>
    </item>
    <item>
      <title>Re: coverting a character variable with number and missing values to numeric variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/coverting-a-character-variable-with-number-and-missing-values-to/m-p/876459#M38913</link>
      <description>&lt;P&gt;The columns of the csv file must appear in the correct order (as stated in the documentation/description of the file) in the INPUT statement, with informats if needed. See the documentation of&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/n0lrz3gb7m9e4rn137op544ddg0v.htm" target="_blank" rel="noopener"&gt;List INPUT&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 May 2023 14:00:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/coverting-a-character-variable-with-number-and-missing-values-to/m-p/876459#M38913</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-05-18T14:00:12Z</dc:date>
    </item>
    <item>
      <title>Re: coverting a character variable with number and missing values to numeric variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/coverting-a-character-variable-with-number-and-missing-values-to/m-p/876460#M38914</link>
      <description>&lt;P&gt;Open your csv file with a text editor (not with Excel!), and copy/paste the first few lines into a window opened with this button:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/54552i914D97BE1B0F21E5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" alt="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 18 May 2023 14:02:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/coverting-a-character-variable-with-number-and-missing-values-to/m-p/876460#M38914</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-05-18T14:02:10Z</dc:date>
    </item>
    <item>
      <title>Re: coverting a character variable with number and missing values to numeric variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/coverting-a-character-variable-with-number-and-missing-values-to/m-p/876476#M38917</link>
      <description>&lt;PRE&gt;"subplotID","flowerID","garden","species","rater","compound","tot.vase.days"
1,"11812",1,1,8,1,25
2,"11713",1,1,7,1,10
3,"11611",1,1,6,1,25
4,"11411",1,1,4,1,23
5,"11112",1,1,1,1,NA
6,"11113",1,1,1,1,NA&lt;/PRE&gt;&lt;P&gt;these are the few lines of my csv file&lt;/P&gt;</description>
      <pubDate>Thu, 18 May 2023 14:55:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/coverting-a-character-variable-with-number-and-missing-values-to/m-p/876476#M38917</guid>
      <dc:creator>Gilles-Protais</dc:creator>
      <dc:date>2023-05-18T14:55:44Z</dc:date>
    </item>
    <item>
      <title>Re: coverting a character variable with number and missing values to numeric variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/coverting-a-character-variable-with-number-and-missing-values-to/m-p/876481#M38918</link>
      <description>&lt;P&gt;Looks like everything except the last column is for identification purposes and should therefore be stored as character.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
infile "......" dlm="," dsdtruncover firstobs=2;
input
  subplotID $
  flowerID $
  garden $
  species $
  rater $
  compound $
  tot_vase_days :mynum.
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 May 2023 15:02:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/coverting-a-character-variable-with-number-and-missing-values-to/m-p/876481#M38918</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-05-18T15:02:43Z</dc:date>
    </item>
    <item>
      <title>Re: coverting a character variable with number and missing values to numeric variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/coverting-a-character-variable-with-number-and-missing-values-to/m-p/876483#M38919</link>
      <description>&lt;P&gt;For a simple file like that I wouldn't bother with doing anything fancy about the NA values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In general the process I follow it to take first line from the file and paste it into the program editor.&amp;nbsp; Remove the quotes and commas (and fix any column headers that are not valid variable names).&amp;nbsp; Then add LENGTH at the front and insert length specifications for each variable so I can convert it into a LENGTH statement to DEFINE the variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But for something this simple I might just use in-line informat specifications in the INPUT statement and let SAS impute the variable type and length from the type and width of the informat used to read the variable. That is because the first 6 variables are all identifier variables and so should be defined as character since you will never be doing arithmetic with the values.&amp;nbsp; To suppress the error messages from the NA value in the one numeric variable I would just add the ?? modifier to the INPUT statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  infile 'myfile.csv' dsd truncover firstobs=2;
  input (subplotID flowerID garden species rater compound) (:$8.) tot_vase_days ??;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 May 2023 15:06:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/coverting-a-character-variable-with-number-and-missing-values-to/m-p/876483#M38919</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-18T15:06:25Z</dc:date>
    </item>
    <item>
      <title>Re: coverting a character variable with number and missing values to numeric variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/coverting-a-character-variable-with-number-and-missing-values-to/m-p/876492#M38920</link>
      <description>&lt;P&gt;Thank you very much.&lt;/P&gt;&lt;P&gt;It Worked for me now.&lt;/P&gt;</description>
      <pubDate>Thu, 18 May 2023 15:26:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/coverting-a-character-variable-with-number-and-missing-values-to/m-p/876492#M38920</guid>
      <dc:creator>Gilles-Protais</dc:creator>
      <dc:date>2023-05-18T15:26:23Z</dc:date>
    </item>
  </channel>
</rss>

