<?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 how to import a weird txt file into sas in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-import-a-weird-txt-file-into-sas/m-p/570272#M160786</link>
    <description>&lt;P&gt;hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;I have got a weird txt files with only 1 column, like:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;id variable value&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01,sex,1&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;23,mat,N&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;78,contin,2&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;34,age,29&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01, job,2&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;06,mat,Y&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;78,sex,2&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ...&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;...&lt;/P&gt;&lt;P&gt;So this txt files with numerous lines shows each variable for each id one by one, which means each id will show up many times for different variables. For example, the first line is saying the sex of 01, the 5th line is saying race of 01 and so forth...&lt;/P&gt;&lt;P&gt;Could anybody help me how to import this kind of txt file into sas (shown below)?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;id&amp;nbsp; &amp;nbsp;sex&amp;nbsp; &amp;nbsp;mat&amp;nbsp; contin job&amp;nbsp; age ...&amp;nbsp; ....&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;02&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;...&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;78&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;...&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 1000&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 05 Jul 2019 13:51:49 GMT</pubDate>
    <dc:creator>ellenqi</dc:creator>
    <dc:date>2019-07-05T13:51:49Z</dc:date>
    <item>
      <title>how to import a weird txt file into sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-import-a-weird-txt-file-into-sas/m-p/570272#M160786</link>
      <description>&lt;P&gt;hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;I have got a weird txt files with only 1 column, like:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;id variable value&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01,sex,1&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;23,mat,N&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;78,contin,2&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;34,age,29&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01, job,2&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;06,mat,Y&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;78,sex,2&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ...&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;...&lt;/P&gt;&lt;P&gt;So this txt files with numerous lines shows each variable for each id one by one, which means each id will show up many times for different variables. For example, the first line is saying the sex of 01, the 5th line is saying race of 01 and so forth...&lt;/P&gt;&lt;P&gt;Could anybody help me how to import this kind of txt file into sas (shown below)?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;id&amp;nbsp; &amp;nbsp;sex&amp;nbsp; &amp;nbsp;mat&amp;nbsp; contin job&amp;nbsp; age ...&amp;nbsp; ....&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;02&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;...&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;78&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;...&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 1000&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jul 2019 13:51:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-import-a-weird-txt-file-into-sas/m-p/570272#M160786</guid>
      <dc:creator>ellenqi</dc:creator>
      <dc:date>2019-07-05T13:51:49Z</dc:date>
    </item>
    <item>
      <title>Re: how to import a weird txt file into sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-import-a-weird-txt-file-into-sas/m-p/570274#M160787</link>
      <description>&lt;P&gt;Read each row as text, parse the three values, sort by ID, then use PROC TRANSPOSE with BY ID; and ID VARIABLE;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jul 2019 14:51:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-import-a-weird-txt-file-into-sas/m-p/570274#M160787</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-07-01T14:51:43Z</dc:date>
    </item>
    <item>
      <title>Re: how to import a weird txt file into sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-import-a-weird-txt-file-into-sas/m-p/570315#M160803</link>
      <description>&lt;P&gt;Looks like you have three variables separated by slash character.&amp;nbsp; You can easily read that.&amp;nbsp; Proc Import could do it, but it is probably easier to just write the data step to read it yourself.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data TALL ;
  length id $10 varaible $32 value $50 ;
  infile 'myfile.txt' dsd dlm='/' truncover firstobs=2;
  input id variable value;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you might want to sort it and use PROC TRANSPOSE to get one row per ID.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=TALL;
  by id variable;
run;

proc transpose data=tall out=WANT(drop=_name_);
  by id;
  var value;
  id variable;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that this reads VALUE as a character variable so all of the resulting variable will also be character.&amp;nbsp; You might want to convert some of the variable into numeric values.&amp;nbsp; You might be able to do that easier while the file is in the TALL format.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;nvalue=input(value,32.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you could convert the numeric and character variable separately.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=TALL out=charvars(drop=_name_);
  where variable in ('cig');
  by id;
  var value;
  id variable;
run;
proc transpose data=TALL out=numvars(drop=_name_);
  where variable not in ('cig');
  by id;
  var nvalue;
  id variable;
run;
data want;
  merge charvars numvars;
  by id;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jul 2019 16:24:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-import-a-weird-txt-file-into-sas/m-p/570315#M160803</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-01T16:24:23Z</dc:date>
    </item>
  </channel>
</rss>

