<?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 if all records for a subject are missing in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Flag-if-all-records-for-a-subject-are-missing/m-p/730687#M227556</link>
    <description>Hey so actually I wanted to create a Boolean variable for the class variable and then use it with SQL max and group by to collapse it to 1 row per ID. At first, I did class=‘HIGH’ but this didn’t work as it won’t capture someone who has all records missing. All records missing also need to be counted as value of 1 for Boolean variable. I tried highind=class=‘HIGH’ but this didn’t work. So I was thinking if I used highind=Missingflag=1 or class=‘HIGH’ then this might work?</description>
    <pubDate>Thu, 01 Apr 2021 13:43:12 GMT</pubDate>
    <dc:creator>tarheel13</dc:creator>
    <dc:date>2021-04-01T13:43:12Z</dc:date>
    <item>
      <title>Flag if all records for a subject are missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flag-if-all-records-for-a-subject-are-missing/m-p/730669#M227551</link>
      <description>&lt;P&gt;is there a way to create a flag for if all records for a subject are missing? Here is some fake example data. I want to flag 002 since its only record is missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID. &amp;nbsp; class&lt;/P&gt;
&lt;P&gt;001 HIGH&lt;/P&gt;
&lt;P&gt;001 LOW&lt;/P&gt;
&lt;P&gt;002&amp;nbsp;&lt;/P&gt;
&lt;P&gt;003 HIGH&lt;/P&gt;
&lt;P&gt;004 LOW&lt;/P&gt;</description>
      <pubDate>Thu, 01 Apr 2021 12:50:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flag-if-all-records-for-a-subject-are-missing/m-p/730669#M227551</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2021-04-01T12:50:49Z</dc:date>
    </item>
    <item>
      <title>Re: Flag if all records for a subject are missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flag-if-all-records-for-a-subject-are-missing/m-p/730679#M227553</link>
      <description>&lt;P&gt;You can use the MISSING function, which will pick up on missing numeric or character values. It's my preferred way since it has that dual-effect.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if missing(class) then flag = "1";
else flag = "0";

/* alternatively, not my preferred method */

if class = "" then flag = "1";
else flag = "0";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Not sure if you're trying to summarize any missing record to ID's, so let us know if that's what you mean.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Apr 2021 13:25:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flag-if-all-records-for-a-subject-are-missing/m-p/730679#M227553</guid>
      <dc:creator>maguiremq</dc:creator>
      <dc:date>2021-04-01T13:25:48Z</dc:date>
    </item>
    <item>
      <title>Re: Flag if all records for a subject are missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flag-if-all-records-for-a-subject-are-missing/m-p/730683#M227554</link>
      <description>&lt;P&gt;You have to pass through each ID twice - the first time to check for non-missing class and setting the flag, and the second time to output the data with the flag value.&amp;nbsp; In the absence of a working data set, here is an untested program.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have (in=firstpass) have (in=secondpass);
  by id;
  retain flag ;
  if first.id then flag=0;
  if firstpass and missing(class)=0 then flag=1;
  if secondpass;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The program requires dataset HAVE to be sorted by ID.&amp;nbsp; The SET statement (with the associated "BY ID;") reads each ID in HAVE twice, but allows only the secondpass to be kept in the output dataset.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Apr 2021 13:31:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flag-if-all-records-for-a-subject-are-missing/m-p/730683#M227554</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-04-01T13:31:33Z</dc:date>
    </item>
    <item>
      <title>Re: Flag if all records for a subject are missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flag-if-all-records-for-a-subject-are-missing/m-p/730687#M227556</link>
      <description>Hey so actually I wanted to create a Boolean variable for the class variable and then use it with SQL max and group by to collapse it to 1 row per ID. At first, I did class=‘HIGH’ but this didn’t work as it won’t capture someone who has all records missing. All records missing also need to be counted as value of 1 for Boolean variable. I tried highind=class=‘HIGH’ but this didn’t work. So I was thinking if I used highind=Missingflag=1 or class=‘HIGH’ then this might work?</description>
      <pubDate>Thu, 01 Apr 2021 13:43:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flag-if-all-records-for-a-subject-are-missing/m-p/730687#M227556</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2021-04-01T13:43:12Z</dc:date>
    </item>
    <item>
      <title>Re: Flag if all records for a subject are missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flag-if-all-records-for-a-subject-are-missing/m-p/730694#M227559</link>
      <description>&lt;P&gt;I'm sorry, I'm not quite understanding. What do you want for your first ID? Is there an inherent order? Do you want the highest value on top? Not sure if this is exactly what you're looking for:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines missover;
input id :$3. class :$4.;
datalines;
001 HIGH
001 LOW
002 
003 HIGH
004 LOW
;

proc sql;
	select
				distinct id,
				class,
				case 
					when class = "HIGH" then 3
					when class = "LOW" then 2
					when missing(class) then 1
						else 0
				end as value
	from
				have
	group by
				id
	having
				value = max(value);
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I'm assuming you want the highest value on top for each record.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;id class value 
001 HIGH 3 
002   1 
003 HIGH 3 
004 LOW 2 
&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Apr 2021 14:02:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flag-if-all-records-for-a-subject-are-missing/m-p/730694#M227559</guid>
      <dc:creator>maguiremq</dc:creator>
      <dc:date>2021-04-01T14:02:38Z</dc:date>
    </item>
    <item>
      <title>Re: Flag if all records for a subject are missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flag-if-all-records-for-a-subject-are-missing/m-p/730713#M227564</link>
      <description>No I wanted a flag for if all their records were missing so that I could use it in a Boolean variable.</description>
      <pubDate>Thu, 01 Apr 2021 14:20:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flag-if-all-records-for-a-subject-are-missing/m-p/730713#M227564</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2021-04-01T14:20:19Z</dc:date>
    </item>
    <item>
      <title>Re: Flag if all records for a subject are missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flag-if-all-records-for-a-subject-are-missing/m-p/730724#M227569</link>
      <description>&lt;P&gt;Does this flag if all records are missing within a subject?&lt;/P&gt;</description>
      <pubDate>Thu, 01 Apr 2021 14:47:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flag-if-all-records-for-a-subject-are-missing/m-p/730724#M227569</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2021-04-01T14:47:22Z</dc:date>
    </item>
    <item>
      <title>Re: Flag if all records for a subject are missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flag-if-all-records-for-a-subject-are-missing/m-p/730728#M227571</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/181158"&gt;@tarheel13&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;No I wanted a flag for if all their records were missing so that I could use it in a Boolean variable.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Please show us the desired output.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Apr 2021 14:48:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flag-if-all-records-for-a-subject-are-missing/m-p/730728#M227571</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-04-01T14:48:57Z</dc:date>
    </item>
    <item>
      <title>Re: Flag if all records for a subject are missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flag-if-all-records-for-a-subject-are-missing/m-p/730734#M227574</link>
      <description>&lt;P&gt;Since 002 only has 1 record and it's missing, I want the missingflag=1. If there was another ID that had 2 records and both were missing, then I also want that to be missingflag=1. Does that make sense?&lt;/P&gt;</description>
      <pubDate>Thu, 01 Apr 2021 15:00:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flag-if-all-records-for-a-subject-are-missing/m-p/730734#M227574</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2021-04-01T15:00:40Z</dc:date>
    </item>
    <item>
      <title>Re: Flag if all records for a subject are missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flag-if-all-records-for-a-subject-are-missing/m-p/730964#M227678</link>
      <description>&lt;P&gt;Sorry. I found an error in my code .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID  class $;
cards;
001 HIGH
001 LOW
002  .
003 HIGH
004 LOW
;

proc sql;
create table want as
select *,n(class) = 0 as flag
 from have
  group by id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 04 Apr 2021 10:52:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flag-if-all-records-for-a-subject-are-missing/m-p/730964#M227678</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-04-04T10:52:02Z</dc:date>
    </item>
    <item>
      <title>Re: Flag if all records for a subject are missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flag-if-all-records-for-a-subject-are-missing/m-p/731021#M227699</link>
      <description>Thanks. Huge fan of SQL!</description>
      <pubDate>Fri, 02 Apr 2021 18:49:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flag-if-all-records-for-a-subject-are-missing/m-p/731021#M227699</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2021-04-02T18:49:03Z</dc:date>
    </item>
    <item>
      <title>Re: Flag if all records for a subject are missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flag-if-all-records-for-a-subject-are-missing/m-p/731024#M227700</link>
      <description>Wait doesn’t the argument have to be a numeric value for nmiss function?</description>
      <pubDate>Fri, 02 Apr 2021 18:52:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flag-if-all-records-for-a-subject-are-missing/m-p/731024#M227700</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2021-04-02T18:52:21Z</dc:date>
    </item>
    <item>
      <title>Re: Flag if all records for a subject are missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flag-if-all-records-for-a-subject-are-missing/m-p/731216#M227781</link>
      <description>That is for Data Step . But For SQL you can apply nmiss() , n() ... to either character or numeric type variables .</description>
      <pubDate>Sun, 04 Apr 2021 10:47:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flag-if-all-records-for-a-subject-are-missing/m-p/731216#M227781</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-04-04T10:47:04Z</dc:date>
    </item>
    <item>
      <title>Re: Flag if all records for a subject are missing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flag-if-all-records-for-a-subject-are-missing/m-p/731236#M227785</link>
      <description>&lt;P&gt;Cool, I just ran it and it worked!&lt;/P&gt;</description>
      <pubDate>Sun, 04 Apr 2021 14:42:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flag-if-all-records-for-a-subject-are-missing/m-p/731236#M227785</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2021-04-04T14:42:47Z</dc:date>
    </item>
  </channel>
</rss>

