<?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 Data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reading-Data/m-p/505806#M135500</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Read the third field as SOURCE, with a trailing @&amp;nbsp; to hold the column pointer. The first two fields are read into a dummy variable, to be dropped later.&lt;/LI&gt;
&lt;LI&gt;Use the value of source to guide re-reading of the line.&amp;nbsp; BUT ...&amp;nbsp; you have to move the pointer back to column 1.&amp;nbsp; That's the "@1" in the code below.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA results2;
  input dummy :$6. dummy :$6. source @;
  if source=1      then input @1 id name $ source score;
  else if source=2 then input @1 id score source name $;
  drop dummy ;
DATALINES;
11 john 1 77
11 88 2 james
22 bobby 1 55
22 89 2 opey
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;You&amp;nbsp; also could push (and hold) the pointer at column 1 in the first input.&amp;nbsp; Then the subsequent input's don't need the "@1".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA results2;
  input dummy :$6. dummy :$6. source @1 @;
  if source=1      then input id name $ source score;
  else if source=2 then input id score source name $;
  drop dummy  ;
DATALINES;
11 john 1 77
11 88 2 james
22 bobby 1 55
22 89 2 opey
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 19 Oct 2018 00:14:32 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2018-10-19T00:14:32Z</dc:date>
    <item>
      <title>Reading Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-Data/m-p/505793#M135492</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I am attempting to read in the results2.data data set so that it looks like the below output. However, when I try to I get an output that has the 4 variables below but only has values for source, and the values are 11, 11, 22,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The data residing in the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="instructure_file_holder link_holder"&gt;&lt;A title="results2.dat" href="https://psu.instructure.com/courses/1900406/files/93873142/download?verifier=rHDq6azoTeb8PUC4yiE96uA6ynG0l4ds6tnd3mUm&amp;amp;wrap=1" target=""&gt;results2.dat&lt;/A&gt;&lt;A title="Preview the document" href="https://psu.instructure.com/courses/1900406/files/93873142/download?verifier=rHDq6azoTeb8PUC4yiE96uA6ynG0l4ds6tnd3mUm&amp;amp;wrap=1" target="_blank"&gt;&lt;IMG src="https://psu.instructure.com/images/preview.png" border="0" alt="Preview the document" /&gt;&lt;/A&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;raw data file came from two different sources (1 and 2). If the value in column 10 is 1, the data in that record came from source 1. If the value in column 10 is 2, the data in that record came from source 2. In short, your job is to read the data file into a SAS data set called&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;results2&lt;/EM&gt;, so that when printed it looks like this:&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://psu.instructure.com/courses/1900406/files/93873151/preview?verifier=9irtQqPLAzLk5WF20dXgpZ5R6VTxaUtCRapOhjYg" border="0" alt="homeworkL21_image03.gif" /&gt;&lt;/P&gt;&lt;P&gt;In order to do this, you'll need to:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Read in the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;source&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;first. Tell SAS to hold the record in the input buffer.&lt;/LI&gt;&lt;LI&gt;Use an if&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;source&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;... then input ... else input ... statement to tell SAS the appropriate order of the variables. If&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;source&lt;/EM&gt;= 1, then specify the variables in your INPUT statement in this order:&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;id&lt;/EM&gt;,&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;name&lt;/EM&gt;,&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;source&lt;/EM&gt;, and&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;score&lt;/EM&gt;. If&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;source&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;= 2, then specify the variables in your INPUT statement in this order:&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;id&lt;/EM&gt;,&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;score&lt;/EM&gt;,&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;source&lt;/EM&gt;, and&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;name&lt;/EM&gt;.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Then, print the resulting SAS data set.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Oct 2018 23:06:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-Data/m-p/505793#M135492</guid>
      <dc:creator>paperboy22</dc:creator>
      <dc:date>2018-10-18T23:06:08Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-Data/m-p/505800#M135495</link>
      <description>&lt;P&gt;We can't see the example data. Copy some rows using a plain text editor and paste into a code box on the forum opened using the {I} icon.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use a trailing @ sign to hold the buffer on an input statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;input source 10 @;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;so you could use the value of source for different input statements:&lt;/P&gt;
&lt;P&gt;if source = 1 then input &amp;lt;what ever is needed&amp;gt;;&lt;/P&gt;
&lt;P&gt;else if source=2 then input &amp;lt;the other info&amp;gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The details of the input are up to you.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Oct 2018 23:34:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-Data/m-p/505800#M135495</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-10-18T23:34:41Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-Data/m-p/505802#M135496</link>
      <description>&lt;P&gt;Sorry, this is the data set:&amp;nbsp;&lt;/P&gt;&lt;DIV class="textLayer--absolute"&gt;11 john 1 77&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;11 88 2 james&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;22 bobby 1 55&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;22 89 2 opey&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;This is the code I have written so far with the output it creates at the bottom: OPTIONS PS=58 LS=72 NODATE NONUMBER;&lt;BR /&gt;LIBNAME stat481 'C:\stat481\data';&lt;BR /&gt;DATA results2;&lt;BR /&gt;input source 10@;&lt;BR /&gt;if source=1 then input id name $ source score;&lt;BR /&gt;else if source=2 then input id score source name $;&lt;BR /&gt;DATALINES;&lt;BR /&gt;11 john 1 77&lt;BR /&gt;11 88 2 james&lt;BR /&gt;22 bobby 1 55&lt;BR /&gt;22 89 2 opey&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;BR /&gt;PROC PRINT Data=results2 NOOBS;&lt;BR /&gt;Title 'The results2 data set';&lt;BR /&gt;RUN;&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;Output&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;The results2 data set&lt;BR /&gt;&lt;BR /&gt;source id name score&lt;BR /&gt;&lt;BR /&gt;88 77 11 2&lt;BR /&gt;89 55 22 2&lt;BR /&gt;&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV class="textLayer--absolute"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Thu, 18 Oct 2018 23:54:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-Data/m-p/505802#M135496</guid>
      <dc:creator>paperboy22</dc:creator>
      <dc:date>2018-10-18T23:54:39Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-Data/m-p/505806#M135500</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Read the third field as SOURCE, with a trailing @&amp;nbsp; to hold the column pointer. The first two fields are read into a dummy variable, to be dropped later.&lt;/LI&gt;
&lt;LI&gt;Use the value of source to guide re-reading of the line.&amp;nbsp; BUT ...&amp;nbsp; you have to move the pointer back to column 1.&amp;nbsp; That's the "@1" in the code below.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA results2;
  input dummy :$6. dummy :$6. source @;
  if source=1      then input @1 id name $ source score;
  else if source=2 then input @1 id score source name $;
  drop dummy ;
DATALINES;
11 john 1 77
11 88 2 james
22 bobby 1 55
22 89 2 opey
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;You&amp;nbsp; also could push (and hold) the pointer at column 1 in the first input.&amp;nbsp; Then the subsequent input's don't need the "@1".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA results2;
  input dummy :$6. dummy :$6. source @1 @;
  if source=1      then input id name $ source score;
  else if source=2 then input id score source name $;
  drop dummy  ;
DATALINES;
11 john 1 77
11 88 2 james
22 bobby 1 55
22 89 2 opey
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Oct 2018 00:14:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-Data/m-p/505806#M135500</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-10-19T00:14:32Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-Data/m-p/505812#M135504</link>
      <description>&lt;P&gt;That worked, thank you for your help.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Oct 2018 00:29:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-Data/m-p/505812#M135504</guid>
      <dc:creator>paperboy22</dc:creator>
      <dc:date>2018-10-19T00:29:29Z</dc:date>
    </item>
  </channel>
</rss>

