<?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: reading values that include both numbers and letters from cvs using proc import in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/reading-values-that-include-both-numbers-and-letters-from-cvs/m-p/710417#M19718</link>
    <description>&lt;P&gt;When reading from a delimited file you want to use list mode input.&amp;nbsp; With list mode the width of the informat is ignored.&amp;nbsp; So your choices are limited to reading it into a character variable or creating your own informat.&lt;/P&gt;
&lt;P&gt;For the first option you could then convert the string to a number using the INPUT() function.&amp;nbsp; You could also define the character variable to have a length a just 1 and the other characters will be ignored when the line is read since there will be no place the store them.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test1;
  infile 'myfile.csv' dsd trucover ;
  input id gender :$1. ;
  gender_code = input(gender,1.);
run;

proc format ;
  infile gender (upcase)
   '1 FEMALE'=1 '2 MALE'=2 
  ;
run;

data test2;
  inflie 'myfile.csv' dsd truncover ;
  input id gender_code :gender. ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 10 Jan 2021 05:44:15 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-01-10T05:44:15Z</dc:date>
    <item>
      <title>reading values that include both numbers and letters from cvs using proc import</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/reading-values-that-include-both-numbers-and-letters-from-cvs/m-p/710409#M19717</link>
      <description>&lt;P&gt;I need to read a cvs file that has value such as "1 female" (for the sex variable) and I would like to read this value into a numeric variable that will have the value of 1 for females&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Yoav&lt;/P&gt;</description>
      <pubDate>Sun, 10 Jan 2021 01:59:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/reading-values-that-include-both-numbers-and-letters-from-cvs/m-p/710409#M19717</guid>
      <dc:creator>yoavgn</dc:creator>
      <dc:date>2021-01-10T01:59:28Z</dc:date>
    </item>
    <item>
      <title>Re: reading values that include both numbers and letters from cvs using proc import</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/reading-values-that-include-both-numbers-and-letters-from-cvs/m-p/710417#M19718</link>
      <description>&lt;P&gt;When reading from a delimited file you want to use list mode input.&amp;nbsp; With list mode the width of the informat is ignored.&amp;nbsp; So your choices are limited to reading it into a character variable or creating your own informat.&lt;/P&gt;
&lt;P&gt;For the first option you could then convert the string to a number using the INPUT() function.&amp;nbsp; You could also define the character variable to have a length a just 1 and the other characters will be ignored when the line is read since there will be no place the store them.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test1;
  infile 'myfile.csv' dsd trucover ;
  input id gender :$1. ;
  gender_code = input(gender,1.);
run;

proc format ;
  infile gender (upcase)
   '1 FEMALE'=1 '2 MALE'=2 
  ;
run;

data test2;
  inflie 'myfile.csv' dsd truncover ;
  input id gender_code :gender. ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 10 Jan 2021 05:44:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/reading-values-that-include-both-numbers-and-letters-from-cvs/m-p/710417#M19718</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-01-10T05:44:15Z</dc:date>
    </item>
    <item>
      <title>Re: reading values that include both numbers and letters from cvs using proc import</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/reading-values-that-include-both-numbers-and-letters-from-cvs/m-p/710418#M19719</link>
      <description>&lt;P&gt;Thanks a lot Tom&lt;/P&gt;&lt;P&gt;The problem is that I have many values like that. For example income is coded "1 21k-25k" "2 26k-30K" etc. Is there a way to extract just the numerical part of the value?&lt;/P&gt;</description>
      <pubDate>Sun, 10 Jan 2021 05:54:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/reading-values-that-include-both-numbers-and-letters-from-cvs/m-p/710418#M19719</guid>
      <dc:creator>yoavgn</dc:creator>
      <dc:date>2021-01-10T05:54:45Z</dc:date>
    </item>
    <item>
      <title>Re: reading values that include both numbers and letters from cvs using proc import</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/reading-values-that-include-both-numbers-and-letters-from-cvs/m-p/710460#M19720</link>
      <description>&lt;P&gt;Read the values as the strings they are and then create new numeric variables from them.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data step1;
  infile 'myfile.csv' dsd truncover;
  length id cvar1-cvar10 $80 ;
  input id cvar1-cvar10;
run;
data step2;
  set step1;
  array old cvar1-cvar10;
  array new nvar1-nvar10;
  do index=1 to dim(old);
    new[index]=input(scan(old[index],1,' '),32.);
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 10 Jan 2021 17:18:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/reading-values-that-include-both-numbers-and-letters-from-cvs/m-p/710460#M19720</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-01-10T17:18:19Z</dc:date>
    </item>
    <item>
      <title>Re: reading values that include both numbers and letters from cvs using proc import</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/reading-values-that-include-both-numbers-and-letters-from-cvs/m-p/710503#M19721</link>
      <description>&lt;P&gt;Meanwhile I found a real easy solution. One way to to it is, for example when the value for female is "2 female" your state sexn=input(sex,1.) and if turns sex into a mumeric variable sexn.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jan 2021 06:44:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/reading-values-that-include-both-numbers-and-letters-from-cvs/m-p/710503#M19721</guid>
      <dc:creator>yoavgn</dc:creator>
      <dc:date>2021-01-11T06:44:41Z</dc:date>
    </item>
  </channel>
</rss>

