<?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 Reading certain number of variables according to a condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reading-certain-number-of-variables-according-to-a-condition/m-p/607194#M176433</link>
    <description>&lt;P&gt;For example below&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Peter &amp;nbsp;2 &amp;nbsp;14 &amp;nbsp;16&lt;/P&gt;&lt;P&gt;James &amp;nbsp;3 &amp;nbsp;17 &amp;nbsp;19 &amp;nbsp;18&lt;/P&gt;&lt;P&gt;Max &amp;nbsp;1 &amp;nbsp;7&lt;/P&gt;&lt;P&gt;Logan &amp;nbsp;5 &amp;nbsp;19 &amp;nbsp;15 &amp;nbsp;11 &amp;nbsp;9 &amp;nbsp;18&lt;/P&gt;&lt;P&gt;…&lt;/P&gt;&lt;P&gt;…&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First variable is Name, Second variable is number of visit and others are amounts.&lt;/P&gt;&lt;P&gt;Peter visited twice so there are 2 amount variables and James visited three times so there are 3 amount variables.&lt;/P&gt;&lt;P&gt;&lt;STRIKE&gt;I want to create a single data step that can read different number of variables according to a condition (# of visits).&lt;/STRIKE&gt;&lt;/P&gt;&lt;P&gt;&lt;STRIKE&gt;And also sum of amount variables for each person.&lt;/STRIKE&gt;&lt;/P&gt;&lt;P&gt;Is it possible to just ignore reading Amount variables and just calculate sum of amount variables for each person and running total of the total amount variables for each person in a single data step?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ex.)&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Name&amp;nbsp; &amp;nbsp;TotalAmt&amp;nbsp; Runtotal&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Peter&amp;nbsp; &amp;nbsp; 30&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 30&lt;/P&gt;&lt;P&gt;James&amp;nbsp; 54&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 84&lt;/P&gt;&lt;P&gt;Max&amp;nbsp; &amp;nbsp; &amp;nbsp; 7&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 91&lt;/P&gt;&lt;P&gt;Logan&amp;nbsp; 72&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;163&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 26 Nov 2019 11:25:46 GMT</pubDate>
    <dc:creator>skjhzzang</dc:creator>
    <dc:date>2019-11-26T11:25:46Z</dc:date>
    <item>
      <title>Reading certain number of variables according to a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-certain-number-of-variables-according-to-a-condition/m-p/607194#M176433</link>
      <description>&lt;P&gt;For example below&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Peter &amp;nbsp;2 &amp;nbsp;14 &amp;nbsp;16&lt;/P&gt;&lt;P&gt;James &amp;nbsp;3 &amp;nbsp;17 &amp;nbsp;19 &amp;nbsp;18&lt;/P&gt;&lt;P&gt;Max &amp;nbsp;1 &amp;nbsp;7&lt;/P&gt;&lt;P&gt;Logan &amp;nbsp;5 &amp;nbsp;19 &amp;nbsp;15 &amp;nbsp;11 &amp;nbsp;9 &amp;nbsp;18&lt;/P&gt;&lt;P&gt;…&lt;/P&gt;&lt;P&gt;…&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First variable is Name, Second variable is number of visit and others are amounts.&lt;/P&gt;&lt;P&gt;Peter visited twice so there are 2 amount variables and James visited three times so there are 3 amount variables.&lt;/P&gt;&lt;P&gt;&lt;STRIKE&gt;I want to create a single data step that can read different number of variables according to a condition (# of visits).&lt;/STRIKE&gt;&lt;/P&gt;&lt;P&gt;&lt;STRIKE&gt;And also sum of amount variables for each person.&lt;/STRIKE&gt;&lt;/P&gt;&lt;P&gt;Is it possible to just ignore reading Amount variables and just calculate sum of amount variables for each person and running total of the total amount variables for each person in a single data step?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ex.)&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Name&amp;nbsp; &amp;nbsp;TotalAmt&amp;nbsp; Runtotal&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Peter&amp;nbsp; &amp;nbsp; 30&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 30&lt;/P&gt;&lt;P&gt;James&amp;nbsp; 54&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 84&lt;/P&gt;&lt;P&gt;Max&amp;nbsp; &amp;nbsp; &amp;nbsp; 7&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 91&lt;/P&gt;&lt;P&gt;Logan&amp;nbsp; 72&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;163&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2019 11:25:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-certain-number-of-variables-according-to-a-condition/m-p/607194#M176433</guid>
      <dc:creator>skjhzzang</dc:creator>
      <dc:date>2019-11-26T11:25:46Z</dc:date>
    </item>
    <item>
      <title>Re: Reading certain number of variables according to a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-certain-number-of-variables-according-to-a-condition/m-p/607196#M176434</link>
      <description>&lt;P&gt;You can't have a varying number of variables per row. But you can organize your data in a long format and you can have a varying number of rows per name. That's what the code below does.&lt;/P&gt;
&lt;P&gt;It's also much easier to work with data in a long format (less variable, more rows). Many of the SAS Procedures then allow you to easily aggregate such data for analysis and reporting purposes.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sample(drop=_:);
  infile datalines truncover;
  input name $ n_vals @;
  do _i=1 to n_vals;
    input amt @;
    output;
  end;
  datalines;
Peter 2 14 16
James 3 17 19 18
Max 1 7
Logan 5 19 15 11 9 18
;

proc print data=sample;
run;

proc sql;
  select 
    name,
    amt,
    sum(amt) as total
  from sample
  group by name
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Nov 2019 05:07:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-certain-number-of-variables-according-to-a-condition/m-p/607196#M176434</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-11-26T05:07:35Z</dc:date>
    </item>
    <item>
      <title>Re: Reading certain number of variables according to a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-certain-number-of-variables-according-to-a-condition/m-p/607201#M176437</link>
      <description>&lt;P&gt;So, do you want to produce a different number of observations for each name (one obs per visit)?&amp;nbsp; That's what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt; has shown you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or do you want one observation per name?&amp;nbsp; If would have differing number of non-missing values for a fixed set of variables (where the fixed set would be sufficient to accommodate the largest number of visits in your sample).&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2019 05:25:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-certain-number-of-variables-according-to-a-condition/m-p/607201#M176437</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-11-26T05:25:50Z</dc:date>
    </item>
  </channel>
</rss>

