<?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: Multiple Parts of a Variable in one line of data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Multiple-Parts-of-a-Variable-in-one-line-of-data/m-p/692404#M210937</link>
    <description>Thank you so much. This is just what I wanted.&lt;BR /&gt;</description>
    <pubDate>Sun, 18 Oct 2020 21:12:05 GMT</pubDate>
    <dc:creator>angelface123ish</dc:creator>
    <dc:date>2020-10-18T21:12:05Z</dc:date>
    <item>
      <title>Multiple Parts of a Variable in one line of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-Parts-of-a-Variable-in-one-line-of-data/m-p/692360#M210910</link>
      <description>&lt;P&gt;How could I assign each age to each corresponding name if the data looks like this?&lt;/P&gt;&lt;P&gt;data siblings;&lt;BR /&gt;input siblingnames $ age @@;&lt;/P&gt;&lt;P&gt;datalines;&lt;BR /&gt;cindy brianna lindsey steven jayden&lt;BR /&gt;23 20 16 22 11&lt;/P&gt;&lt;P&gt;;&lt;BR /&gt;proc print;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Sun, 18 Oct 2020 14:31:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-Parts-of-a-Variable-in-one-line-of-data/m-p/692360#M210910</guid>
      <dc:creator>angelface123ish</dc:creator>
      <dc:date>2020-10-18T14:31:11Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple Parts of a Variable in one line of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-Parts-of-a-Variable-in-one-line-of-data/m-p/692367#M210913</link>
      <description>&lt;P&gt;First thing is to make sure any example data step recreates your current data.&lt;/P&gt;
&lt;P&gt;Since that data step as provided generates errors then it pretty obviously does not represent your data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is your question how to read the data? Not obvious from the phrasing. And if your actual data has more columns or more rows the following may not work though may be extendable&lt;/P&gt;
&lt;PRE&gt;data siblings;
informat name1-name5 $10.;
input name1-name5
     /age1-age5
;

datalines;
cindy brianna lindsey steven jayden
23 20 16 22 11
;

/* if you want one row per name/age*/
data want;
   set siblings;
   array n name1-name5;
   array a age1-age5;
   length name $10.;
   do i=1 to dim(n);
     name=n[i];
     age =a[i];
     output;
   end;
   keep name age;
run;
&lt;/PRE&gt;
&lt;P&gt;The / in the INPUT statement say "continue reading on next line".&lt;/P&gt;
&lt;P&gt;Doing similar operations with multiple variables is the purpose of ARRAYs , to create a shorthand way of referencing the variables with an index value so multiple related values can be addressed.&lt;/P&gt;
&lt;P&gt;The output in the second data step tells SAS when to explicitly write to the output data step, once for each name/age pair. The keep says which variables should be in the output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If by any chance this poorly structured data came from a spreadsheet you might consider using the spreadsheet tools to transpose the rows to columns before doing anything with SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hints with datalines: do not have empty lines or leading spaces. Such may cause unexpected results.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Oct 2020 13:44:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-Parts-of-a-Variable-in-one-line-of-data/m-p/692367#M210913</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-10-19T13:44:38Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple Parts of a Variable in one line of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-Parts-of-a-Variable-in-one-line-of-data/m-p/692370#M210915</link>
      <description>Thank you so much for this. I was thinking about an array but wasn't quite sure how to go about it. I truly appreciate it.</description>
      <pubDate>Sun, 18 Oct 2020 15:39:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-Parts-of-a-Variable-in-one-line-of-data/m-p/692370#M210915</guid>
      <dc:creator>angelface123ish</dc:creator>
      <dc:date>2020-10-18T15:39:18Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple Parts of a Variable in one line of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-Parts-of-a-Variable-in-one-line-of-data/m-p/692371#M210916</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/352985"&gt;@angelface123ish&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an option without arrays:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data siblings(drop=_:);
length siblingname $15;
infile datalines col=pos;
do _v=1 to 10; /* or, after an "input @;" statement: ... to 2*countw(_infile_) */
  if mod(_v,2) then do; 
    input #1 @_n siblingname @;
    _n=pos;
  end;
  else do;
    input #2 @_a age @;
    _a=pos;
    output;
  end;
end;
datalines;
cindy brianna lindsey steven jayden
23 20 16 22 11
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 18 Oct 2020 15:49:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-Parts-of-a-Variable-in-one-line-of-data/m-p/692371#M210916</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-10-18T15:49:09Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple Parts of a Variable in one line of data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-Parts-of-a-Variable-in-one-line-of-data/m-p/692404#M210937</link>
      <description>Thank you so much. This is just what I wanted.&lt;BR /&gt;</description>
      <pubDate>Sun, 18 Oct 2020 21:12:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-Parts-of-a-Variable-in-one-line-of-data/m-p/692404#M210937</guid>
      <dc:creator>angelface123ish</dc:creator>
      <dc:date>2020-10-18T21:12:05Z</dc:date>
    </item>
  </channel>
</rss>

