<?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: Running a function for each unique value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Running-a-function-for-each-unique-value/m-p/375957#M90185</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id $ x $ ;
cards;
ID1 BMI
ID1 CHOL
ID1 GLUCOSE
ID1 BP
ID2 CHOL
ID2 GLUCOSE
;
run;
proc sql;
select *,case when count(distinct x)=4 then 1 else 0 end as flag
 from have
  group by id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 14 Jul 2017 09:35:41 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2017-07-14T09:35:41Z</dc:date>
    <item>
      <title>Running a function for each unique value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-a-function-for-each-unique-value/m-p/375874#M90161</link>
      <description>Hello,&lt;BR /&gt;&lt;BR /&gt;I am wondering if it's possible to check whether a condition is satisfied for every unique ID in my dataset. For example,&lt;BR /&gt;&lt;BR /&gt;ID1 BMI&lt;BR /&gt;ID1 CHOL&lt;BR /&gt;ID1 GLUCOSE&lt;BR /&gt;ID1 BP&lt;BR /&gt;ID2 CHOL&lt;BR /&gt;ID2 GLUCOSE&lt;BR /&gt;&lt;BR /&gt;So for ID1, their biometrics screenings would be complete (I was thinking of creating a new variable called biometrics that equals 1 if all 4 are there). However, for ID2, since the person only has two of the 4, biometrics would be 0, indicating that the individual is not up-to-date with his biometrics. Is this at all possible? Thanks.</description>
      <pubDate>Fri, 14 Jul 2017 00:03:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-a-function-for-each-unique-value/m-p/375874#M90161</guid>
      <dc:creator>corkee</dc:creator>
      <dc:date>2017-07-14T00:03:46Z</dc:date>
    </item>
    <item>
      <title>Re: Running a function for each unique value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-a-function-for-each-unique-value/m-p/375876#M90162</link>
      <description>&lt;P&gt;Can you have multiple entries for a particular screen? Ie BMI&amp;nbsp;is collected twice?&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2017 00:11:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-a-function-for-each-unique-value/m-p/375876#M90162</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-07-14T00:11:14Z</dc:date>
    </item>
    <item>
      <title>Re: Running a function for each unique value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-a-function-for-each-unique-value/m-p/375877#M90163</link>
      <description>&lt;P&gt;Are they all on one record for a given ID, or on multiple records? Regardless, what is/are the variables called?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2017 00:15:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-a-function-for-each-unique-value/m-p/375877#M90163</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-07-14T00:15:02Z</dc:date>
    </item>
    <item>
      <title>Re: Running a function for each unique value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-a-function-for-each-unique-value/m-p/375878#M90164</link>
      <description>&lt;P&gt;Hi Reeza. So my dataset is actually a lot more confusing than the example I provided. There's a difference between BMI_current and BMI, but I just wanted to get help on a more general level and adjust the code as needed. Let's say BMI isn't collected twice.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2017 00:18:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-a-function-for-each-unique-value/m-p/375878#M90164</guid>
      <dc:creator>corkee</dc:creator>
      <dc:date>2017-07-14T00:18:49Z</dc:date>
    </item>
    <item>
      <title>Re: Running a function for each unique value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-a-function-for-each-unique-value/m-p/375879#M90165</link>
      <description>Hi art, they are on multiple records. The ID variable is ID and the screening variable is called ActionName.</description>
      <pubDate>Fri, 14 Jul 2017 00:16:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-a-function-for-each-unique-value/m-p/375879#M90165</guid>
      <dc:creator>corkee</dc:creator>
      <dc:date>2017-07-14T00:16:55Z</dc:date>
    </item>
    <item>
      <title>Re: Running a function for each unique value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-a-function-for-each-unique-value/m-p/375882#M90167</link>
      <description>&lt;P&gt;I think you are asking if you can do something like:&lt;/P&gt;
&lt;PRE&gt;data have;
  input id ActionName $;
  cards;
1 BMI
1 CHOL
1 GLUCOSE
1 BP
2 BMI
2 CHOL
3 BMI
3 CHOL
3 GLUCOSE
3 OTHER
4 BMI
4 CHOL
4 GLUCOSE
4 BP
;
data want;
  do until(last.id);
    set have;
    by id;
    if first.id then biometrics=0;
    if ActionName='BMI' then biometrics=sum(biometrics,.0001);
    else if ActionName='CHOL' then biometrics=sum(biometrics,.0010);
    else if ActionName='GLUCOSE' then biometrics=sum(biometrics,.0100);
    else if ActionName='BP' then biometrics=sum(biometrics,.1000);
    if last.id then if biometrics eq .1111 then output /*or something else*/ ;
  end;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2017 00:37:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-a-function-for-each-unique-value/m-p/375882#M90167</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-07-14T00:37:42Z</dc:date>
    </item>
    <item>
      <title>Re: Running a function for each unique value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-a-function-for-each-unique-value/m-p/375903#M90172</link>
      <description>&lt;P&gt;Hi, another idea ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;data have;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;input id x :$7. @@;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;datalines;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;1 BMI 1 CHOL 1 GLUCOSE 1 BP&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;2 BMI 2 CHOL 3 BMI 3 CHOL&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;3 GLUCOSE 3 OTHER 4 BMI 4 CHOL&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;4 GLUCOSE 4 BP 4 OTHER 4 DUDE&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;* find maximum number of observations within an ID;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;proc sql noprint;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;select max(count) into :max from&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;(select count(*) as count from have group by id);&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;* reshape data, one observation per ID;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;proc summary data=have nway;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;class id;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;output out=have2 (drop=_: ) idgroup(out[&amp;amp;max] (x)=);&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;data want;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;set have2;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;array x_(&amp;amp;max);&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;all4 = ('BMI' in x_) &amp;amp; ('CHOL' in x_) &amp;amp; ('GLUCOSE' in x_) &amp;amp; ('BP' in x_);&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA SET: want

id    x_1    x_2       x_3      x_4       x_5     x_6     all4

 1    BMI    CHOL    GLUCOSE    BP                          1
 2    BMI    CHOL                                           0
 3    BMI    CHOL    GLUCOSE    OTHER                       0
 4    BMI    CHOL    GLUCOSE    BP       OTHER    DUDE      1
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or, using a bit of Art's approach ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;data want (keep=id all4);&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;array x_(50) $7;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;do j=1 by 1 until(last.id);&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&amp;nbsp; set have;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&amp;nbsp; by id;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;&amp;nbsp; x_(j) = x;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;end;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;all4 = ('BMI' in x_) &amp;amp; ('CHOL' in x_) &amp;amp; ('GLUCOSE' in x_) &amp;amp; ('BP' in x_);&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA SET: want

id    all4

 1      1
 2      0
 3      0
 4      1
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 14 Jul 2017 03:13:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-a-function-for-each-unique-value/m-p/375903#M90172</guid>
      <dc:creator>MikeZdeb</dc:creator>
      <dc:date>2017-07-14T03:13:18Z</dc:date>
    </item>
    <item>
      <title>Re: Running a function for each unique value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-a-function-for-each-unique-value/m-p/375957#M90185</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id $ x $ ;
cards;
ID1 BMI
ID1 CHOL
ID1 GLUCOSE
ID1 BP
ID2 CHOL
ID2 GLUCOSE
;
run;
proc sql;
select *,case when count(distinct x)=4 then 1 else 0 end as flag
 from have
  group by id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 14 Jul 2017 09:35:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-a-function-for-each-unique-value/m-p/375957#M90185</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-07-14T09:35:41Z</dc:date>
    </item>
  </channel>
</rss>

