<?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: How to remove any blank colums on a row by row basis in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-any-blank-colums-on-a-row-by-row-basis/m-p/516287#M139430</link>
    <description>&lt;P&gt;Maxim 19: Don't keep Data in Structure&lt;/P&gt;
&lt;P&gt;Which means: don't put the session number in column names. Use the same three columns throughout, and put the session number in it's own column. This "long" dataset will be much easier to work with.&lt;/P&gt;</description>
    <pubDate>Tue, 27 Nov 2018 12:17:17 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-11-27T12:17:17Z</dc:date>
    <item>
      <title>How to remove any blank colums on a row by row basis</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-any-blank-colums-on-a-row-by-row-basis/m-p/516278#M139425</link>
      <description>&lt;P&gt;I'm working with a team for the upcoming season, and have been tasked with compiling statistics tracking data after every session (training and/or game), and creating cumulative variables based on the data. In addition to creating the cumulative variables, I need to append the relevant variables from the previous 3 sessions that each player has attended, in order to track progression.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The variables that I&amp;nbsp;need to keep from each sessions are called : Distance, Sprint_Distance &amp;amp; Top_Speed. The session data is extracted in CSV format for any player that has attended, and I append each sessions data&amp;nbsp;to a master session dataset, which I need to be in order to create a count of how many sessions each player has attended. When reading in the session data, I append a numeric value to the end of each field, which indicates the session number. So session&amp;nbsp;1 will have field names:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Distance_1&lt;/P&gt;&lt;P&gt;Sprint_Distance_1&lt;/P&gt;&lt;P&gt;Top_Speed_1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Session 2 will have '_2' appended at the end, session 3 has '_3' appended&amp;nbsp;and so on for each subsequent session.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;While I've created the cumulative variables&amp;nbsp;using the MEAN function, I'm having trouble extracting the data from the previous 3 sessions&amp;nbsp;for each player. What I've tried is the following, extracting the last record and then deleting it so the next step will not extract the same record.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data previous1&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sessions1;&lt;BR /&gt;set path.raw_session_data;&lt;BR /&gt;by Player_Name;&lt;BR /&gt;if last.Player_Name then output previous1;&lt;BR /&gt;if last.Player_Name then delete;&lt;BR /&gt;output sessions1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data previous2&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sessions2;&lt;BR /&gt;set sessions1;&lt;BR /&gt;by Player_Name;&lt;BR /&gt;if last.Player_Name then output previous2;&lt;BR /&gt;if last.Player_Name then delete;&lt;BR /&gt;output sessions2;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data previous3&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sessions3;&lt;BR /&gt;set sessions2;&lt;BR /&gt;by Player_Name;&lt;BR /&gt;if last.Player_Name then output previous3;&lt;BR /&gt;if last.Player_Name then delete;&lt;BR /&gt;output sessions3;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data prev_sessions;&lt;BR /&gt;merge previous1&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; previous2&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; previous3;&lt;BR /&gt;by Player_Name;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I'm looking to do is to keep only the&amp;nbsp;variables where data is available when identifying the last 3 sessions attended,&amp;nbsp;instead of appending all session variables to each of the previous1-3 datasets being created. The problem is that I don't know the variable names that will be extracted, as players won't have attended every session so far. For example, player 1 has attended sessions 1, 2, 4 and 6, player 2 has attended sessions 1, 3,&amp;nbsp;5 and&amp;nbsp;6, player 3 has attended all sessions&amp;nbsp;1, 2, 3, 4, 5, 6&amp;nbsp;etc. so these numbers will be appended to the variable names as outlined previously.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will then need to rename the variables to something like :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Previous_Distance_1 for the most recent previous session;&lt;/P&gt;&lt;P&gt;Previous_Distance_2 for the second most recent previous session;&lt;/P&gt;&lt;P&gt;Previous_Distance_3 for the third most recent previous session;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hopefully I'm making sense!! Any help will be greatly appreciated!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Nov 2018 11:14:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-any-blank-colums-on-a-row-by-row-basis/m-p/516278#M139425</guid>
      <dc:creator>ciaranhillery</dc:creator>
      <dc:date>2018-11-27T11:14:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove any blank colums on a row by row basis</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-any-blank-colums-on-a-row-by-row-basis/m-p/516282#M139428</link>
      <description>&lt;P&gt;Post test data in the form of a datastep:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Show what the output you want from that test data is.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Nov 2018 11:33:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-any-blank-colums-on-a-row-by-row-basis/m-p/516282#M139428</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-11-27T11:33:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove any blank colums on a row by row basis</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-any-blank-colums-on-a-row-by-row-basis/m-p/516287#M139430</link>
      <description>&lt;P&gt;Maxim 19: Don't keep Data in Structure&lt;/P&gt;
&lt;P&gt;Which means: don't put the session number in column names. Use the same three columns throughout, and put the session number in it's own column. This "long" dataset will be much easier to work with.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Nov 2018 12:17:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-any-blank-colums-on-a-row-by-row-basis/m-p/516287#M139430</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-11-27T12:17:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove any blank colums on a row by row basis</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-any-blank-colums-on-a-row-by-row-basis/m-p/516288#M139431</link>
      <description>&lt;P&gt;Due to restrictions with the connection where I am working from at present, I'm unable to create the dataset using the linked instructions. Below is a manual creation of the input session data&amp;nbsp;- hope this works!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; WORK&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token statement"&gt;CLASS&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;label&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'Session Data'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN class="token statement"&gt;infile&lt;/SPAN&gt; datalines dsd truncover&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt; Name:&lt;SPAN class="token punctuation"&gt;$10&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt; Distance_1:&lt;SPAN class="token punctuation"&gt;$10&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt; Sprint_Distance_1:&lt;SPAN class="token punctuation"&gt;$10&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt; Top_Speed_1:$10.;&lt;BR /&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token keyword"&gt;datalines&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token data string"&gt;Player1&amp;nbsp;5.5397&amp;nbsp;1259.38&amp;nbsp;8.009 &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token data string"&gt;Player2 5.9846&amp;nbsp;1009.018 7.5334&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token data string"&gt;Player3 6.1655&amp;nbsp;913.654&amp;nbsp;7.7067 &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token data string"&gt;Player4 6.2424&amp;nbsp;881.055&amp;nbsp;7.9001 &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token data string"&gt;Player5 6.1148&amp;nbsp;1010.969&amp;nbsp;8.089 &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token punctuation"&gt;This will be repeated for subsequent sessions, but if any of players 1-5 didn't attend, then no data will be appended for them.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token punctuation"&gt;When trying to extract the last 3 sessions attended per player, the steps listed on the initial steps&amp;nbsp;will append all fields to date i.e. Distance_1-6 etc. I only need to keep the final 3 that are populated.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="token punctuation"&gt;What I'm ultimately looking for would be something like:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;Player Name&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Number of Sessions attended&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Average Distance (km)&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Previous Distance 1&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Previous Distance 2&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Previous Distance 3&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Average Sprint Distance (m)&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Previous Sprint Distance 1&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Previous Sprint Distance 2&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Previous Sprint Distance 3&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Average Top Speed&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Previous Top Speed 1&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Previous Top Speed 2&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Previous Top Speed 3&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Player1&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;6.44056&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;1350.05&lt;/TD&gt;&lt;TD&gt;D&lt;/TD&gt;&lt;TD&gt;E&lt;/TD&gt;&lt;TD&gt;F&lt;/TD&gt;&lt;TD&gt;8.01428&lt;/TD&gt;&lt;TD&gt;G&lt;/TD&gt;&lt;TD&gt;H&lt;/TD&gt;&lt;TD&gt;I&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Tue, 27 Nov 2018 12:26:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-any-blank-colums-on-a-row-by-row-basis/m-p/516288#M139431</guid>
      <dc:creator>ciaranhillery</dc:creator>
      <dc:date>2018-11-27T12:26:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove any blank colums on a row by row basis</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-any-blank-colums-on-a-row-by-row-basis/m-p/516290#M139433</link>
      <description>&lt;P&gt;How would this work when I need to merge the needed&amp;nbsp;variables together, and then ultimately trying to create the averages?&lt;/P&gt;</description>
      <pubDate>Tue, 27 Nov 2018 12:36:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-any-blank-colums-on-a-row-by-row-basis/m-p/516290#M139433</guid>
      <dc:creator>ciaranhillery</dc:creator>
      <dc:date>2018-11-27T12:36:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove any blank colums on a row by row basis</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-any-blank-colums-on-a-row-by-row-basis/m-p/516298#M139436</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/248162"&gt;@ciaranhillery&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;How would this work when I need to merge the needed&amp;nbsp;variables together, and then ultimately trying to create the averages?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You use by-group processing in the relevant procedures. The "wide" format prevents this effectively, and is therefore not used for processing, only for display when data is prepared for human consumption.&lt;/P&gt;
&lt;P&gt;See this as a short example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WORK.CLASS1;
input Name :$10. Distance Sprint_Distance_1 Top_Speed_1;
datalines;
Player1 5.5397 1259.38 8.009
Player2 5.9846 1009.018 7.5334
Player3 6.1655 913.654 7.7067
Player4 6.2424 881.055 7.9001
Player5 6.1148 1010.969 8.089
;
run;

data WORK.CLASS2;
input Name :$10. Distance Sprint_Distance Top_Speed;
datalines;
Player1 5.5397 1259.38 8.009
Player2 5.9846 1009.018 7.5334
Player3 6.1655 913.654 7.7067
Player5 6.1148 1010.969 8.089
;
run;

data WORK.CLASS3;
input Name :$10. Distance Sprint_Distance Top_Speed;
datalines;
Player1 5.5397 1259.38 8.009
Player2 5.9846 1009.018 7.5334
Player4 6.2424 881.055 7.9001
Player5 6.1148 1010.969 8.089
;
run;

data all;
set work.class: indsname=inds;
session = input(substr(scan(inds,2,'.'),6),best.);
run;

proc sort data=all;
by name;
run;

proc means data=all mean;
by name;
var Distance Sprint_Distance_1 Top_Speed_1;
output out=want mean()=;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Nov 2018 13:01:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-any-blank-colums-on-a-row-by-row-basis/m-p/516298#M139436</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-11-27T13:01:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove any blank colums on a row by row basis</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-any-blank-colums-on-a-row-by-row-basis/m-p/516301#M139438</link>
      <description>&lt;P&gt;Just make a vertical dataset instead.&amp;nbsp; Assuming that you already have the data in this format where the variable names in each dataset is different then here is a quick way to get it into a more normal structure.&amp;nbsp; This assumes that the individual datasets are already sorted by player_name.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  length Player_Name $30 session_no Distance Sprint_Distance Top_Speed 8;
  set session_1 - session_6 ;
  by player_name;
  if first.player_name then session_no=0;
  session_no+1;
  distance = coalesce(of distance_:);
  sprint_distance = coalesce(of sprint_distance_:);
  top_speed = coalesce(of top_speed_:);
  keep player_name -- top_speed;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Nov 2018 13:23:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-any-blank-colums-on-a-row-by-row-basis/m-p/516301#M139438</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-11-27T13:23:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove any blank colums on a row by row basis</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-any-blank-colums-on-a-row-by-row-basis/m-p/516348#M139455</link>
      <description>&lt;P&gt;Thanks Tom, I've been able to work around this code to get what I need.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you to everyone for getting back to me!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Nov 2018 15:33:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-any-blank-colums-on-a-row-by-row-basis/m-p/516348#M139455</guid>
      <dc:creator>ciaranhillery</dc:creator>
      <dc:date>2018-11-27T15:33:56Z</dc:date>
    </item>
  </channel>
</rss>

