<?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: Flag variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Flag-variable/m-p/622079#M182962</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/255656"&gt;@luvscandy27&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The dataset above was created using first. last. I was trying to remove the obs I don't need using first.last. &lt;BR /&gt;I tried the code below but it does not keep all the obs where first_year eq 1:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;set datal; &lt;BR /&gt;by ssn first_year;&lt;BR /&gt;if first.first_year;&lt;BR /&gt;run;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The IF FIRST.&amp;lt;variable name&amp;gt; syntax returns the first row of a sorted set and not all rows with a specific value.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try one of the options below for what you want.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data data1;
  infile datalines delimiter = ',';
  input customerid $ year regdate:mmddyy10. completedate:mmddyy10. first_ssn
    last_ssn first_year last_year;
  format regdate completedate mmddyy10.;
  datalines;
100, 2019,04/30/2019, 01/24/2018, 1,0,1,0
100,2018,12/31/2018,12/16/2019, 0,0,0,0
100,2018,11/30/2018,12/16/2019, 0,0,0,1
100,2019, 08/31/2019,12/16/2019,0,0,1,0
;
run;

proc print data=data1(where=(first_year=1));
run;

data want1;
  set data1(where=(first_year=1));
run;

data want2;
  set data1;
  where first_year=1;
run;

data want3;
  set data1;
  if first_year=1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 04 Feb 2020 00:47:37 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2020-02-04T00:47:37Z</dc:date>
    <item>
      <title>Flag variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flag-variable/m-p/622072#M182958</link>
      <description>&lt;P&gt;I have the following data below. I would like to choose the obs where &lt;BR /&gt;first_year eq 1. I would like my data set to look like the table below &lt;BR /&gt;could someone assist me with this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data data1;&lt;BR /&gt;infile datalines delimiter = ',';&lt;BR /&gt;input customerid $ year regdate:mmddyy10. completedate:mmddyy10. first_ssn &lt;BR /&gt;last_ssn first_year last_year;&lt;BR /&gt;format regdate completedate mmddyy10.;&lt;BR /&gt;datalines;&lt;BR /&gt;100, 2019,04/30/2019, 01/24/2018, 1,0,1,0&lt;BR /&gt;100,2018,12/31/2018,12/16/2019, 0,0,0,0&lt;BR /&gt;100,2018,11/30/2018,12/16/2019, 0,0,0,1&lt;BR /&gt;100,2019, 08/31/2019,12/16/2019,0,0,1,0&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;TABLE width="568"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="77"&gt;customerid&lt;/TD&gt;
&lt;TD width="64"&gt;year&lt;/TD&gt;
&lt;TD width="76"&gt;regdate&lt;/TD&gt;
&lt;TD width="95"&gt;completedate&lt;/TD&gt;
&lt;TD width="64"&gt;first_ssn&lt;/TD&gt;
&lt;TD width="64"&gt;last_ssn&lt;/TD&gt;
&lt;TD width="64"&gt;first_year&lt;/TD&gt;
&lt;TD width="64"&gt;last_year&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;100&lt;/TD&gt;
&lt;TD&gt;2019&lt;/TD&gt;
&lt;TD&gt;4/30/2019&lt;/TD&gt;
&lt;TD&gt;1/24/2018&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;100&lt;/TD&gt;
&lt;TD&gt;2019&lt;/TD&gt;
&lt;TD&gt;8/31/2019&lt;/TD&gt;
&lt;TD&gt;12/16/2019&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Tue, 04 Feb 2020 00:05:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flag-variable/m-p/622072#M182958</guid>
      <dc:creator>luvscandy27</dc:creator>
      <dc:date>2020-02-04T00:05:40Z</dc:date>
    </item>
    <item>
      <title>Re: Flag variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flag-variable/m-p/622073#M182959</link>
      <description>&lt;P&gt;Generic form to create a subset of data based on an existing&amp;nbsp;variable for a given value:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; where variable=1;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may not even need to create a new data set as you can use data set options such as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc print data=have (where=(variable=1));&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;to select the records to use as needed.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2020 00:11:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flag-variable/m-p/622073#M182959</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-02-04T00:11:11Z</dc:date>
    </item>
    <item>
      <title>Re: Flag variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flag-variable/m-p/622075#M182960</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The dataset above was created using first. last. I was trying to remove the obs I don't need using first.last. &lt;BR /&gt;I tried the code below but it does not keep all the obs where first_year eq 1:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;set datal; &lt;BR /&gt;by ssn first_year;&lt;BR /&gt;if first.first_year;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2020 00:21:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flag-variable/m-p/622075#M182960</guid>
      <dc:creator>luvscandy27</dc:creator>
      <dc:date>2020-02-04T00:21:11Z</dc:date>
    </item>
    <item>
      <title>Re: Flag variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flag-variable/m-p/622079#M182962</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/255656"&gt;@luvscandy27&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The dataset above was created using first. last. I was trying to remove the obs I don't need using first.last. &lt;BR /&gt;I tried the code below but it does not keep all the obs where first_year eq 1:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;set datal; &lt;BR /&gt;by ssn first_year;&lt;BR /&gt;if first.first_year;&lt;BR /&gt;run;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The IF FIRST.&amp;lt;variable name&amp;gt; syntax returns the first row of a sorted set and not all rows with a specific value.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try one of the options below for what you want.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data data1;
  infile datalines delimiter = ',';
  input customerid $ year regdate:mmddyy10. completedate:mmddyy10. first_ssn
    last_ssn first_year last_year;
  format regdate completedate mmddyy10.;
  datalines;
100, 2019,04/30/2019, 01/24/2018, 1,0,1,0
100,2018,12/31/2018,12/16/2019, 0,0,0,0
100,2018,11/30/2018,12/16/2019, 0,0,0,1
100,2019, 08/31/2019,12/16/2019,0,0,1,0
;
run;

proc print data=data1(where=(first_year=1));
run;

data want1;
  set data1(where=(first_year=1));
run;

data want2;
  set data1;
  where first_year=1;
run;

data want3;
  set data1;
  if first_year=1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Feb 2020 00:47:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flag-variable/m-p/622079#M182962</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-02-04T00:47:37Z</dc:date>
    </item>
  </channel>
</rss>

