<?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 Rows to columns in a single data step. in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Rows-to-columns-in-a-single-data-step/m-p/866254#M38296</link>
    <description>&lt;P&gt;Hello! I have 2 rows of data;&lt;BR /&gt;&lt;BR /&gt;2010 2011 2012 2013 2014 2015&lt;/P&gt;&lt;P&gt;13456 15673 12003 18546 14111 13872&lt;BR /&gt;&lt;BR /&gt;I want to import this data with only 1 data step so that my first row (representing years) becomes column "years" and my second row (representing income) becomes column "income".&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I have tried a lot, like using&amp;nbsp;@@, : and so on. Nothing seems to work. Maybe someone over here can give me a hint. Thank you.&lt;/P&gt;</description>
    <pubDate>Sat, 25 Mar 2023 01:33:29 GMT</pubDate>
    <dc:creator>Etaren</dc:creator>
    <dc:date>2023-03-25T01:33:29Z</dc:date>
    <item>
      <title>Rows to columns in a single data step.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Rows-to-columns-in-a-single-data-step/m-p/866254#M38296</link>
      <description>&lt;P&gt;Hello! I have 2 rows of data;&lt;BR /&gt;&lt;BR /&gt;2010 2011 2012 2013 2014 2015&lt;/P&gt;&lt;P&gt;13456 15673 12003 18546 14111 13872&lt;BR /&gt;&lt;BR /&gt;I want to import this data with only 1 data step so that my first row (representing years) becomes column "years" and my second row (representing income) becomes column "income".&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I have tried a lot, like using&amp;nbsp;@@, : and so on. Nothing seems to work. Maybe someone over here can give me a hint. Thank you.&lt;/P&gt;</description>
      <pubDate>Sat, 25 Mar 2023 01:33:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Rows-to-columns-in-a-single-data-step/m-p/866254#M38296</guid>
      <dc:creator>Etaren</dc:creator>
      <dc:date>2023-03-25T01:33:29Z</dc:date>
    </item>
    <item>
      <title>Re: Rows to columns in a single data step.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Rows-to-columns-in-a-single-data-step/m-p/866256#M38297</link>
      <description>&lt;P&gt;Do you know how many there are in advance?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  infile myfile truncover length=ll column=cc;
  input year1-year6 / income1-income6 ;
  array y [6] ;
  array i [6] ;
  do row=1 to 6;
    year=y[row];
    income=i[row];
    output;
  end;
  keep row year income;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If not then just make the array larger than you could need and count how many years there so you know how many incomes to read.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  array y [1000] _temporary_;
  infile myfile truncover length=ll column=cc;
  do row=1 by 1 until (cc&amp;gt;ll);
    input y[row] @@;
  end;
  input;
  do row=1 to row ;
    year=y[row];
    input income @@;
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 25 Mar 2023 02:29:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Rows-to-columns-in-a-single-data-step/m-p/866256#M38297</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-03-25T02:29:06Z</dc:date>
    </item>
    <item>
      <title>Re: Rows to columns in a single data step.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Rows-to-columns-in-a-single-data-step/m-p/866282#M38304</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options parmcards=x;
filename x temp;
parmcards;
2010 2011 2012 2013 2014 2015
13456 15673 12003 18546 14111 13872
;



data want;
 infile x length=len;
 length first second $ 2000;
 retain first;
 if _n_=1 then input first $varying2000. len;
 if _n_=2 then do;
  input second $varying2000. len;
  do i=1 to countw(first);
    year=input(scan(first,i),best32.);
	income=input(scan(second,i),best32.);
	output;
  end;
 end;
 keep year income;
 run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 25 Mar 2023 10:25:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Rows-to-columns-in-a-single-data-step/m-p/866282#M38304</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-03-25T10:25:19Z</dc:date>
    </item>
    <item>
      <title>Re: Rows to columns in a single data step.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Rows-to-columns-in-a-single-data-step/m-p/866292#M38305</link>
      <description>&lt;P&gt;It can be done also using two filenames pointing to your data file:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename x1 "/home/.../Two lines of data.txt";

filename x2 "/home/.../Two lines of data.txt";

data want;
infile x1 firstobs=1 obs=1 truncover;
input year @@;
if missing(year) then stop;
infile x2 firstobs=2 obs=2;
input income @@;
output;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 25 Mar 2023 19:44:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Rows-to-columns-in-a-single-data-step/m-p/866292#M38305</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2023-03-25T19:44:47Z</dc:date>
    </item>
    <item>
      <title>Re: Rows to columns in a single data step.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Rows-to-columns-in-a-single-data-step/m-p/866297#M38306</link>
      <description>&lt;P&gt;The key trick there is two make the data step believe it is reading form two different files otherwise it only opens the file once in spite of two infile statements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you could use two different filerefs.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename file1 "c:\downloads\sample.txt" ;
filename file2 "%sysfunc(pathname(file1))";
data want;
  infile file1 obs=1;
  input year @@;
  infile file2 firstobs=2;
  input income @@;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or a fileref and a physical path.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename file1 "c:\downloads\sample.txt" ;
data want;
  infile file1 obs=1;
  input year @@;
  infile "%sysfunc(pathname(file1))" firstobs=2;
  input income @@;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or just two different paths that point to the same file.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  infile "c:\downloads\sample.txt"  obs=1;
  input year @@;
  infile "c:\downloads\.\sample.txt" firstobs=2;
  input income @@;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 25 Mar 2023 20:55:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Rows-to-columns-in-a-single-data-step/m-p/866297#M38306</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-03-25T20:55:50Z</dc:date>
    </item>
    <item>
      <title>Re: Rows to columns in a single data step.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Rows-to-columns-in-a-single-data-step/m-p/866316#M38307</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt; - But, I used exactly the same filepath for both filenames, and it worked. I'm on SODA (Unix servers, I guess).&lt;/P&gt;</description>
      <pubDate>Sat, 25 Mar 2023 23:52:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Rows-to-columns-in-a-single-data-step/m-p/866316#M38307</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2023-03-25T23:52:58Z</dc:date>
    </item>
    <item>
      <title>Re: Rows to columns in a single data step.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Rows-to-columns-in-a-single-data-step/m-p/866323#M38308</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt; - But, I used exactly the same filepath for both filenames, and it worked. I'm on SODA (Unix servers, I guess).&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You did not use "filepaths" on either of the INFILE statements in your data step.&amp;nbsp; You used two different&amp;nbsp;&lt;STRONG&gt;filerefs&lt;/STRONG&gt;.&lt;/P&gt;</description>
      <pubDate>Sun, 26 Mar 2023 05:53:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Rows-to-columns-in-a-single-data-step/m-p/866323#M38308</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-03-26T05:53:12Z</dc:date>
    </item>
    <item>
      <title>Re: Rows to columns in a single data step.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Rows-to-columns-in-a-single-data-step/m-p/866383#M38309</link>
      <description>&lt;P&gt;Thank you all so much for your solutions!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Mar 2023 14:45:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Rows-to-columns-in-a-single-data-step/m-p/866383#M38309</guid>
      <dc:creator>Etaren</dc:creator>
      <dc:date>2023-03-26T14:45:14Z</dc:date>
    </item>
    <item>
      <title>Re: Rows to columns in a single data step.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Rows-to-columns-in-a-single-data-step/m-p/866393#M38310</link>
      <description>&lt;P&gt;These solutions started me thinking ... would there be any value to SAS implementing column pointers for each row of the input buffer?&amp;nbsp; For example, could this approach be made to work with some tweaks to the software?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   infile rawdata stopover;
   input  #1 year  #2 income @@;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And would this be a tiny step toward implementing some functionality of Python or R within the SAS software?&lt;/P&gt;</description>
      <pubDate>Sun, 26 Mar 2023 16:50:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Rows-to-columns-in-a-single-data-step/m-p/866393#M38310</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2023-03-26T16:50:57Z</dc:date>
    </item>
  </channel>
</rss>

