<?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: Importing raw files with inconsistent records and assigning column names to only a few in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Importing-raw-files-with-inconsistent-records-and-assigning/m-p/390849#M93812</link>
    <description>&lt;P&gt;Hi Shmuel,&lt;BR /&gt;Thanks for the reply,&lt;BR /&gt;However, apologies on my part, i forgot to mention that I have raw lines which dont have &amp;lt; such as:&lt;BR /&gt;&lt;BR /&gt;Temperature : 56&lt;BR /&gt;&lt;BR /&gt;I am currently using many IF statements for my scan function. The only thing unique about these rows that do not have column names are that they contain a number with a %.&lt;BR /&gt;&lt;BR /&gt;for the code here&lt;BR /&gt;&lt;BR /&gt;else do;&lt;BR /&gt;i+1;&lt;BR /&gt;col_name = 'Arm1_Yield_' || suffix(i);&lt;BR /&gt;col_value = raw_line;&lt;BR /&gt;end;&lt;BR /&gt;&lt;BR /&gt;I have also columns for Arm2_Yield , All_Yield etc as seen in the picture above,&lt;BR /&gt;at this rate I would have duplicate column names in my final data set. I need SAS to recognize these names and then assign the approriate suffix respectively.&lt;/P&gt;</description>
    <pubDate>Fri, 25 Aug 2017 08:48:29 GMT</pubDate>
    <dc:creator>Sharvthegreat</dc:creator>
    <dc:date>2017-08-25T08:48:29Z</dc:date>
    <item>
      <title>Importing raw files with inconsistent records and assigning column names to only a few</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-raw-files-with-inconsistent-records-and-assigning/m-p/390831#M93804</link>
      <description>&lt;P&gt;I am currently trying to import a txt file into sas most of the line have a column name followed by the respective values,&lt;/P&gt;&lt;P&gt;EXCEPT for this... the column name is on one line followed by another 4 values which are a subset of the first line as shown below for Arm_Yield, what I need to do is to assign respective subcolumn names to each record.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I get SAS to assign a value based on the specific row, given I have to import multiples of these txt files and the values are constantly changing. Good thing is they are always on the same line for each file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The picture on the left is what I am currently at, On the right is what I want to have.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Currently i am just using a scan function to split the lines into column and input value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;SAS 9.4&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/14649i6F507DF2228CD639/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Aug 2017 08:05:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-raw-files-with-inconsistent-records-and-assigning/m-p/390831#M93804</guid>
      <dc:creator>Sharvthegreat</dc:creator>
      <dc:date>2017-08-25T08:05:56Z</dc:date>
    </item>
    <item>
      <title>Re: Importing raw files with inconsistent records and assigning column names to only a few</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-raw-files-with-inconsistent-records-and-assigning/m-p/390845#M93809</link>
      <description>&lt;P&gt;Some of your raw lines start with '&amp;lt;' then you can assign:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if substr(left(raw_line),1,1) = '&amp;lt;' then do;
   col_name = scan(raw_line,1,'&amp;lt;&amp;gt;');
   col_value = scan(raw_line,2,'&amp;lt;&amp;gt;');
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Sas will not accept colomn name like '36.84%' as it is nonvalid sas name.&lt;/P&gt;
&lt;P&gt;In such case you may name the variables as var1 var2 ... and assign the '36.84%' as a label to it.&lt;/P&gt;
&lt;P&gt;I see there are various values: 36.84% 60.48% 58.58% 67.47% 43.37% ...etc. - which seems to be unpredictable amount of variables&lt;/P&gt;
&lt;P&gt;and cann't tell if any of them apears once or more times.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I undestand that the right table is the answer/solution to this situation, then, proposed code is&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 set have;
       retain i; drop i;
       array suffix $ _temporary_ {'A' 'B' 'C' 'D'}; /* I'm not sure about exact order/syntax */

if substr(left(raw_line),1,1) = '&amp;lt;' then do;
   col_name = scan(raw_line,1,'&amp;lt;&amp;gt;');
   col_value = scan(raw_line,2,'&amp;lt;&amp;gt;');
   i=0;
end;
else do;
   i+1;
   col_name = 'Arm1_Yield_' || suffix(i);
   col_value = raw_line;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Aug 2017 08:36:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-raw-files-with-inconsistent-records-and-assigning/m-p/390845#M93809</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-08-25T08:36:14Z</dc:date>
    </item>
    <item>
      <title>Re: Importing raw files with inconsistent records and assigning column names to only a few</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-raw-files-with-inconsistent-records-and-assigning/m-p/390849#M93812</link>
      <description>&lt;P&gt;Hi Shmuel,&lt;BR /&gt;Thanks for the reply,&lt;BR /&gt;However, apologies on my part, i forgot to mention that I have raw lines which dont have &amp;lt; such as:&lt;BR /&gt;&lt;BR /&gt;Temperature : 56&lt;BR /&gt;&lt;BR /&gt;I am currently using many IF statements for my scan function. The only thing unique about these rows that do not have column names are that they contain a number with a %.&lt;BR /&gt;&lt;BR /&gt;for the code here&lt;BR /&gt;&lt;BR /&gt;else do;&lt;BR /&gt;i+1;&lt;BR /&gt;col_name = 'Arm1_Yield_' || suffix(i);&lt;BR /&gt;col_value = raw_line;&lt;BR /&gt;end;&lt;BR /&gt;&lt;BR /&gt;I have also columns for Arm2_Yield , All_Yield etc as seen in the picture above,&lt;BR /&gt;at this rate I would have duplicate column names in my final data set. I need SAS to recognize these names and then assign the approriate suffix respectively.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Aug 2017 08:48:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-raw-files-with-inconsistent-records-and-assigning/m-p/390849#M93812</guid>
      <dc:creator>Sharvthegreat</dc:creator>
      <dc:date>2017-08-25T08:48:29Z</dc:date>
    </item>
    <item>
      <title>Re: Importing raw files with inconsistent records and assigning column names to only a few</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-raw-files-with-inconsistent-records-and-assigning/m-p/390862#M93820</link>
      <description>&lt;P&gt;I see, "else" names are a combination of last col_name as prefix and the suffix.&lt;/P&gt;
&lt;P&gt;you can retain the last col_name as prefix.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 set have;
       retain i prefix; 
       array suffix $ ch1-ch4 {'A' 'B' 'C' 'D'}; /* line syntax was fixed */&lt;BR /&gt;       drop i prefix ch1-ch4;&lt;BR /&gt;
if substr(left(raw_line),1,1) = '&amp;lt;' then do;
   col_name = scan(raw_line,1,'&amp;lt;&amp;gt;');
   prefix = col_name;
   col_value = scan(raw_line,2,'&amp;lt;&amp;gt;');
   i=0;
end;
else do;
   i+1;
   col_name = compress(prefix || suffix(i));
   col_value = raw_line;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 Aug 2017 10:23:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-raw-files-with-inconsistent-records-and-assigning/m-p/390862#M93820</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-08-25T10:23:51Z</dc:date>
    </item>
  </channel>
</rss>

