<?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: First but not Blank in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/First-but-not-Blank/m-p/872662#M82689</link>
    <description>&lt;P&gt;Just use a period as a placeholder in the data line for missing value (numeric or character).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data once;
 input ID $ visit1 $ site1 $  ;
CARDS;
Inn342  .    .
Inn342  Anc  Sha
Inn342  Drr  Loc
Pan322  .    .
Pan322  Cli  Dha
Pan322  Omn  Sha
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To move the data backwards in time you need make two passes thru the data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could do it with two separate SET statements.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  do until(last.id);
    set once;
    by id;
    length first_site $8;
    first_site=coalescec(first_site,site1);
  end;
  do until(last.id);
    set once;
    by id;
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you could merge it with itself.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  merge once 
        once(keep=id site1 rename=(site1=xxx) where=(not missing(xxx)))
  ;
  by id;
  if first.id then first_site=xxx;
  retain first_site;
  drop xxx;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 27 Apr 2023 19:57:24 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-04-27T19:57:24Z</dc:date>
    <item>
      <title>First but not Blank</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/First-but-not-Blank/m-p/872642#M82682</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to scan data columns for sites for each ID.&amp;nbsp; I am looking for the following record (where there is no blank) and for that data value to be placed into a new column (Most Recent).&amp;nbsp; I am having difficulty trying to get SAS to bypass the record rows where there is a blank and to pick the next row containing data.&amp;nbsp; Can anyone shed some light?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The first table shows the data the second table shows how I would like the results&amp;nbsp; .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Sanna_K_0-1682622152447.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/83345i9C67BB57B5B4C20C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Sanna_K_0-1682622152447.png" alt="Sanna_K_0-1682622152447.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;DATA&lt;/STRONG&gt; Once;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;INPUT ID $ visit1 site1&amp;nbsp; ;&lt;/P&gt;
&lt;P&gt;CARDS;&lt;/P&gt;
&lt;P&gt;Inn342&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; null&amp;nbsp; null&lt;/P&gt;
&lt;P&gt;Inn342&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Anc&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Sha&lt;/P&gt;
&lt;P&gt;Inn342&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Drr&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Loc&lt;/P&gt;
&lt;P&gt;Pan322&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Pan322&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Cli&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dha&lt;/P&gt;
&lt;P&gt;Pan322&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Omn&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Sha&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;RUN&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Apr 2023 19:04:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/First-but-not-Blank/m-p/872642#M82682</guid>
      <dc:creator>SannaSanna</dc:creator>
      <dc:date>2023-04-27T19:04:41Z</dc:date>
    </item>
    <item>
      <title>Re: First but not Blank</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/First-but-not-Blank/m-p/872644#M82683</link>
      <description>&lt;P&gt;Your data step does not work because you try to read character data into numeric variables. Please fix that, either by making the variables character or providing the necessary code to convert the strings to numbers.&lt;/P&gt;
&lt;P&gt;Once we know how your dataset&amp;nbsp;&lt;EM&gt;really&amp;nbsp;&lt;/EM&gt;looks, we can help you.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Apr 2023 19:10:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/First-but-not-Blank/m-p/872644#M82683</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-04-27T19:10:46Z</dc:date>
    </item>
    <item>
      <title>Re: First but not Blank</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/First-but-not-Blank/m-p/872645#M82684</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12130"&gt;@SannaSanna&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to scan data columns for sites for each ID.&amp;nbsp; I am looking for the following record (where there is no blank) and for that data value to be placed into a new column (Most Recent).&amp;nbsp; I am having difficulty trying to get SAS to bypass the record rows where there is a blank and to pick the next row containing data.&amp;nbsp; Can anyone shed some light?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The first table shows the data the second table shows how I would like the results&amp;nbsp; .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Sanna_K_0-1682622152447.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/83345i9C67BB57B5B4C20C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Sanna_K_0-1682622152447.png" alt="Sanna_K_0-1682622152447.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;DATA&lt;/STRONG&gt; Once;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;INPUT ID $ visit1 site1&amp;nbsp; ;&lt;/P&gt;
&lt;P&gt;CARDS;&lt;/P&gt;
&lt;P&gt;Inn342&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; null&amp;nbsp; null&lt;/P&gt;
&lt;P&gt;Inn342&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Anc&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Sha&lt;/P&gt;
&lt;P&gt;Inn342&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Drr&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Loc&lt;/P&gt;
&lt;P&gt;Pan322&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Pan322&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Cli&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dha&lt;/P&gt;
&lt;P&gt;Pan322&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Omn&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Sha&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;RUN&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Is the text string 'null' in the first row of Inn342 the same as the text string ' ' (empty string) in the first row of Pan322?&lt;/P&gt;</description>
      <pubDate>Thu, 27 Apr 2023 19:12:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/First-but-not-Blank/m-p/872645#M82684</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-04-27T19:12:21Z</dc:date>
    </item>
    <item>
      <title>Re: First but not Blank</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/First-but-not-Blank/m-p/872648#M82685</link>
      <description>&lt;P&gt;I was trying to insert blank data for the first row for the two IDs.&amp;nbsp; The spreadsheet shows blank cell/empty/no data for Inn342 and Pan322 for their most recent record.&amp;nbsp; I want to pick the next row containing data.&amp;nbsp; Sorry- I was not able to insert the blank row for each customer in my cards statement.&amp;nbsp; Can you still&amp;nbsp; help?&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Apr 2023 19:21:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/First-but-not-Blank/m-p/872648#M82685</guid>
      <dc:creator>SannaSanna</dc:creator>
      <dc:date>2023-04-27T19:21:40Z</dc:date>
    </item>
    <item>
      <title>Re: First but not Blank</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/First-but-not-Blank/m-p/872649#M82686</link>
      <description>&lt;P&gt;Are we talking about a SAS dataset here, or an Excel spreadsheet?&lt;/P&gt;
&lt;P&gt;If it is a SAS dataset, which type are visit1 and site1 (character or numeric)?&lt;/P&gt;</description>
      <pubDate>Thu, 27 Apr 2023 19:29:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/First-but-not-Blank/m-p/872649#M82686</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-04-27T19:29:35Z</dc:date>
    </item>
    <item>
      <title>Re: First but not Blank</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/First-but-not-Blank/m-p/872651#M82687</link>
      <description>They are both character in my SAS dataset. (visit1 and site1 contain character data)</description>
      <pubDate>Thu, 27 Apr 2023 19:33:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/First-but-not-Blank/m-p/872651#M82687</guid>
      <dc:creator>SannaSanna</dc:creator>
      <dc:date>2023-04-27T19:33:09Z</dc:date>
    </item>
    <item>
      <title>Re: First but not Blank</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/First-but-not-Blank/m-p/872654#M82688</link>
      <description>&lt;P&gt;So then this DATA step will create your data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dsd truncover;
input ID $ visit1 $ site1 $;
datalines;
Inn342,,
Inn342,Anc,Sha
Inn342,Drr,Loc
Pan322,,
Pan322,Cli,Dha
Pan322,Omn,Sha
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;?&lt;/P&gt;</description>
      <pubDate>Thu, 27 Apr 2023 19:38:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/First-but-not-Blank/m-p/872654#M82688</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-04-27T19:38:17Z</dc:date>
    </item>
    <item>
      <title>Re: First but not Blank</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/First-but-not-Blank/m-p/872662#M82689</link>
      <description>&lt;P&gt;Just use a period as a placeholder in the data line for missing value (numeric or character).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data once;
 input ID $ visit1 $ site1 $  ;
CARDS;
Inn342  .    .
Inn342  Anc  Sha
Inn342  Drr  Loc
Pan322  .    .
Pan322  Cli  Dha
Pan322  Omn  Sha
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To move the data backwards in time you need make two passes thru the data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could do it with two separate SET statements.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  do until(last.id);
    set once;
    by id;
    length first_site $8;
    first_site=coalescec(first_site,site1);
  end;
  do until(last.id);
    set once;
    by id;
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you could merge it with itself.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  merge once 
        once(keep=id site1 rename=(site1=xxx) where=(not missing(xxx)))
  ;
  by id;
  if first.id then first_site=xxx;
  retain first_site;
  drop xxx;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 Apr 2023 19:57:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/First-but-not-Blank/m-p/872662#M82689</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-04-27T19:57:24Z</dc:date>
    </item>
    <item>
      <title>Re: First but not Blank</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/First-but-not-Blank/m-p/872686#M82690</link>
      <description>Thank you so much Tom!  I tweeked the code a little bit to work with my live data and it worked perfectly.  Thank you again so much!  Have a wonderful day!</description>
      <pubDate>Thu, 27 Apr 2023 20:54:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/First-but-not-Blank/m-p/872686#M82690</guid>
      <dc:creator>SannaSanna</dc:creator>
      <dc:date>2023-04-27T20:54:04Z</dc:date>
    </item>
    <item>
      <title>Re: First but not Blank</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/First-but-not-Blank/m-p/872691#M82691</link>
      <description>&lt;P&gt;Tom,&lt;/P&gt;
&lt;P&gt;I used this code:&amp;nbsp;&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;data want;
  do until(last.id);
    set once;
    by id;
    length first_site $8;
    first_site=coalescec(first_site,site1);
  end;
  do until(last.id);
    set once;
    by id;
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was wondering how I could incorporate a county code for the patient to get the same output by county?&amp;nbsp; The table output would look like this:&amp;nbsp; patient Inn342 visited two counties with most recent in 01 is Sha and in county 19 is Dha.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SannaSanna_0-1682630163113.png" style="width: 665px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/83353i8081F9EE904AD0DC/image-dimensions/665x211?v=v2" width="665" height="211" role="button" title="SannaSanna_0-1682630163113.png" alt="SannaSanna_0-1682630163113.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;updated code to include county and blanks. (thank you)&lt;/P&gt;
&lt;P&gt;data once;&lt;BR /&gt;input ID $ county $ visit1 $ site1 $ ;&lt;BR /&gt;CARDS;&lt;BR /&gt;Inn342 01 . .&lt;BR /&gt;Inn342 01 Anc Sha&lt;BR /&gt;Inn342 01 Drr Loc&lt;BR /&gt;Pan322 19 . .&lt;BR /&gt;Pan322 19 Cli Dha&lt;BR /&gt;Pan322 19 Omn Sha&lt;BR /&gt;; run;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Apr 2023 21:18:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/First-but-not-Blank/m-p/872691#M82691</guid>
      <dc:creator>SannaSanna</dc:creator>
      <dc:date>2023-04-27T21:18:35Z</dc:date>
    </item>
  </channel>
</rss>

