<?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: SAS coding in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-coding/m-p/440059#M109870</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31493"&gt;@PhanS&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hello PGStats,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am looking for:&lt;/P&gt;
&lt;P&gt;a)&amp;nbsp;at least one out of the fourth items to be 1 (or yes)&lt;/P&gt;
&lt;P&gt;2) all&amp;nbsp;&lt;SPAN&gt;of the fourth items to be 1 (or yes)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;3) at least 2 out of the four items to be 1 (yes)&lt;/P&gt;
&lt;P&gt;4 at least 3&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;out of the four items to be 1 (yes)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My codes showed the results.&lt;/P&gt;
&lt;P&gt;However, I would like to learn if there such SAS codes that can support mine. In the other words, to have the same results as my analyses.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Phan S.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Since it looks like your variables are coded as missing,0 or 1 then you just need to sum the values to answer those questions.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    n_yes =sum(of FD CL HS HL) ;
    at_least_one=1&amp;lt;= n_yes ;
    at_least_two=2 &amp;lt;= n_yes ;
    at_least_three=3 &amp;lt;= n_yes;
    all_one = 4= n_yes ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 25 Feb 2018 18:54:16 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2018-02-25T18:54:16Z</dc:date>
    <item>
      <title>SAS coding</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-coding/m-p/439875#M109791</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I posted my codes - i wonder if one of you can advise me for a shorter codes than mine. Please kindly see below. Great appreciate your time.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if food= . or cloth= . or cost_h= . or risk_hl= . then do;
if food=1 or cloth=1 or cost_h=1 or risk_hl=1 then any_1bneed=1;
else if food=0 or cloth=0 or cost_h=0 or risk_hl=0 then any_1bneed=0;
else any_1bneed=.;
end;

if food= . or cloth= . or cost_h= . or risk_hl= . then do;
if      food=1 and cloth=1 and cost_h=0 or risk_hl=0 then any_2bneed=1;
else if cost_h=1 and risk_hl=1 and food=0 or cloth=0 then any_2bneed=2;
else if food=1 and cost_h=1 and cloth=0 or risk_hl=0 then any_2bneed=3;
else if food=1 and risk_hl=1 and cloth=0 or cost_h=0 then any_2bneed=4;
else if cloth=1 and cost_h=1 and food=0 or risk_hl=0 then any_2bneed=5;
else if cloth=1 and risk_hl=1 and food=0 or cost_h=0 then any_2bneed=6;
else any_2bneed= .;
end;

if food= . or cloth= . or cost_h= . or risk_hl= . then do;
if      food=1 and cloth=1 and cost_h=1 and risk_hl=0 then any_3bneed=1;
else if food=1 and cloth=1 and cost_h=0 and risk_hl=1 then any_3bneed=2;
else if food=1 and cloth=0 and cost_h=1 and risk_hl=1 then any_2bneed=3;
else if food=0 and cloth=1 and cost_h=1 and risk_hl=1 then any_2bneed=4;
else any_3bneed= .;
end;

if food= . or cloth= . or cost_h= . or risk_hl= . then do;
if food=1 and cloth=1 and cost_h=1 and risk_hl=1 then all_4bneed=1;
else if food=0 and cloth=0 and cost_h=0 and risk_hl=0 then all_4bneed=0;
else all_4bneed=.;
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Feb 2018 21:50:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-coding/m-p/439875#M109791</guid>
      <dc:creator>PhanS</dc:creator>
      <dc:date>2018-02-23T21:50:39Z</dc:date>
    </item>
    <item>
      <title>Re: SAS coding</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-coding/m-p/439880#M109795</link>
      <description>&lt;P&gt;Can you make a table of all your cases and what they map to?&lt;/P&gt;
&lt;P&gt;If you can build that table, you can join it and it'll be cleaner.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ie&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;food cloth cost_h risk_hl group&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Feb 2018 21:58:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-coding/m-p/439880#M109795</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-23T21:58:33Z</dc:date>
    </item>
    <item>
      <title>Re: SAS coding</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-coding/m-p/439884#M109796</link>
      <description>&lt;P&gt;Hi ie,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID @; 
  do time1 to time4;
    input FD CL HS HL @;    
    output; 
  end;
cards; 

1 1 1 1 1 
1 1 . 1 1
. . . . . 
1 1 1 1 1 

2 1 1 1 .   
2 1 1 0 . 
. . . . .  
2 1 1 0 1

3 1 0 0 0  
3 0 0 1 1  
. . . . .
3 1 0 . 1

4 1 0 0 . 
4 0 0 0 .
. . . . . 
4 1 . 0 0

5 0 . 0 0 
5 0 . 0 0  
. . . . .
5 0 0 . 0  

6 1 1 1 1  
6 1 1 1 1 
. . . . .
6 1 1 1 1

7 1 1 1 . 
7 1 1 0 . 
. . . . . 
7 1 1 0 1 
 
8 1 0 0 0 
8 0 0 1 1 
. . . . .
8 1 0 . 1

9 1 0 0 .  
9 0 0 0 . 
. . . . .
9 1 . 0 0

10 0 . 0 0 
10 1 1 0 .  
. . . . .  
10 1 1 0 1 

; 
run;

time 3 do not have data&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 23 Feb 2018 22:16:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-coding/m-p/439884#M109796</guid>
      <dc:creator>PhanS</dc:creator>
      <dc:date>2018-02-23T22:16:00Z</dc:date>
    </item>
    <item>
      <title>Re: SAS coding</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-coding/m-p/439885#M109797</link>
      <description>&lt;P&gt;Note that &lt;EM&gt;any_3bneed&lt;/EM&gt; and &lt;EM&gt;all_4bneed&lt;/EM&gt; will always be missing because, for example,&amp;nbsp;it is impossible for both&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;food= . or cloth= . or cost_h= . or risk_hl= .&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;food=1 and cloth=1 and cost_h=1 and risk_hl=1&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;to be true at the same time.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Feb 2018 22:40:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-coding/m-p/439885#M109797</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-02-23T22:40:51Z</dc:date>
    </item>
    <item>
      <title>Re: SAS coding</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-coding/m-p/439887#M109798</link>
      <description>&lt;P&gt;My question is similar to the one that&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;&amp;nbsp;asked.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You&amp;nbsp;never set&amp;nbsp;any_2bneed or&amp;nbsp;any_3bneed to missing, and you never calculate any of the values unless there is at least one missing value. Is that really what you want to do?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Feb 2018 23:08:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-coding/m-p/439887#M109798</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-02-23T23:08:47Z</dc:date>
    </item>
    <item>
      <title>Re: SAS coding</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-coding/m-p/439892#M109801</link>
      <description>&lt;P&gt;Hello Art,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am looking for:&lt;/P&gt;
&lt;P&gt;a)&amp;nbsp;at least one out of the fourth items to be 1 (or yes)&lt;/P&gt;
&lt;P&gt;2) all&amp;nbsp;&lt;SPAN&gt;of the fourth items to be 1 (or yes)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;3) at least 2 out of the four items to be 1 (yes)&lt;/P&gt;
&lt;P&gt;4 at least 3&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;out of the four items to be 1 (yes)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My codes showed the results.&lt;/P&gt;
&lt;P&gt;However, I would like to learn if there such SAS codes that can support mine. In the other words, to have the same results as my analyses.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Phan S.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 24 Feb 2018 00:10:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-coding/m-p/439892#M109801</guid>
      <dc:creator>PhanS</dc:creator>
      <dc:date>2018-02-24T00:10:49Z</dc:date>
    </item>
    <item>
      <title>Re: SAS coding</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-coding/m-p/439893#M109802</link>
      <description>&lt;P&gt;Hello PGStats,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am looking for:&lt;/P&gt;
&lt;P&gt;a)&amp;nbsp;at least one out of the fourth items to be 1 (or yes)&lt;/P&gt;
&lt;P&gt;2) all&amp;nbsp;&lt;SPAN&gt;of the fourth items to be 1 (or yes)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;3) at least 2 out of the four items to be 1 (yes)&lt;/P&gt;
&lt;P&gt;4 at least 3&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;out of the four items to be 1 (yes)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My codes showed the results.&lt;/P&gt;
&lt;P&gt;However, I would like to learn if there such SAS codes that can support mine. In the other words, to have the same results as my analyses.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Phan S.&lt;/P&gt;</description>
      <pubDate>Sat, 24 Feb 2018 00:11:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-coding/m-p/439893#M109802</guid>
      <dc:creator>PhanS</dc:creator>
      <dc:date>2018-02-24T00:11:29Z</dc:date>
    </item>
    <item>
      <title>Re: SAS coding</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-coding/m-p/439897#M109803</link>
      <description>&lt;P&gt;I don't think your code does what you want. If I'm wrong, just ignore this post.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, I think that the following does do what you want. Notice that I've changed your input dataset in order to&amp;nbsp;capture all of the possible combinations. I accounted for this missing ID values while inputting the data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have (drop=x);
  retain id;
  do time=1 to 4;
    input x FD CL HS HL;
    if not missing(x) then ID=x;
    output; 
  end;
cards; 
1 1 . 0 . 
1 . 1 0 0
. . . 1 . 
1 0 0 0 1 
2 1 1 . .   
2 1 . 1 . 
. 1 . . 1  
2 . 1 1 0
2 . 1 0 1  
2 0 0 1 1  
. . . . .
3 1 1 1 .
3 1 1 . 1 
3 0 1 1 1
. . . . . 
4 1 1 1 1
5 0 . 0 1 
5 0 . 0 0  
. . . . .
5 0 0 . 0  
6 1 1 1 1  
6 1 1 1 1 
. . . . .
6 1 1 1 1
7 1 1 1 . 
7 1 1 0 . 
. . . . . 
7 1 1 0 1 
8 1 0 0 0 
8 0 0 1 1 
. . . . .
8 1 0 . 1
9 1 0 0 .  
9 0 0 0 . 
. . . . .
9 1 . 0 0
10 0 1 . 0 
10 1 1 0 .  
. . . . .  
10 1 1 0 1 
; 
run;

proc format;
  value anytwo
  2='1*2'
  3='1*3'
  4='1*4'
  6='2*3'
  8='2*4'
 12='3*4'
 ;
  value anythree
  6='1*2*3'
  8='1*2*4'
 24='2*3*4'
 ;
run;

data want (drop= i _:);
  set have;
  array items(4) FD CL HS HL;
  array _items(4);
  array needs(4) any_1bneed any_2bneed any_3bneed all_4bneed;
  format any_2bneed anytwo.;
  format any_3bneed anythree.;
  if nmiss(of items(*)) lt 4 then do;
    do i=1 to 4;
      _items(i)=items(i);
      needs(i)=0;
    end;
    if sum(of items(*)) eq 1 then any_1bneed=whichn(1,of items(*));
    else if sum(of items(*)) eq 2 then do;
      any_2bneed=whichn(1,of items(*));
      _items(any_2bneed)=0;
      any_2bneed=any_2bneed*whichn(1,of _items(*));
    end;
    else if sum(of items(*)) eq 3 then do;
      any_3bneed=whichn(1,of items(*));
      _items(any_3bneed)=0;
      any_3bneed=any_3bneed*whichn(1,of _items(*));
      _items(whichn(1,of _items(*)))=0;
      any_3bneed=any_3bneed*whichn(1,of _items(*));
    end;
    else all_4bneed=1;
  end;
run;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Sat, 24 Feb 2018 01:04:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-coding/m-p/439897#M109803</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-02-24T01:04:40Z</dc:date>
    </item>
    <item>
      <title>Re: SAS coding</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-coding/m-p/439899#M109804</link>
      <description>&lt;P&gt;Dear Art,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It appears to be what I am looking for.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many thanks for your help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Phan S.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 24 Feb 2018 01:31:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-coding/m-p/439899#M109804</guid>
      <dc:creator>PhanS</dc:creator>
      <dc:date>2018-02-24T01:31:49Z</dc:date>
    </item>
    <item>
      <title>Re: SAS coding</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-coding/m-p/440059#M109870</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31493"&gt;@PhanS&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hello PGStats,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am looking for:&lt;/P&gt;
&lt;P&gt;a)&amp;nbsp;at least one out of the fourth items to be 1 (or yes)&lt;/P&gt;
&lt;P&gt;2) all&amp;nbsp;&lt;SPAN&gt;of the fourth items to be 1 (or yes)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;3) at least 2 out of the four items to be 1 (yes)&lt;/P&gt;
&lt;P&gt;4 at least 3&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;out of the four items to be 1 (yes)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My codes showed the results.&lt;/P&gt;
&lt;P&gt;However, I would like to learn if there such SAS codes that can support mine. In the other words, to have the same results as my analyses.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Phan S.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Since it looks like your variables are coded as missing,0 or 1 then you just need to sum the values to answer those questions.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    n_yes =sum(of FD CL HS HL) ;
    at_least_one=1&amp;lt;= n_yes ;
    at_least_two=2 &amp;lt;= n_yes ;
    at_least_three=3 &amp;lt;= n_yes;
    all_one = 4= n_yes ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 25 Feb 2018 18:54:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-coding/m-p/440059#M109870</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-02-25T18:54:16Z</dc:date>
    </item>
  </channel>
</rss>

