<?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: Is there any function  to find the observation value across the variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Is-there-any-function-to-find-the-observation-value-across-the/m-p/731109#M227738</link>
    <description>&lt;P&gt;"Y" and "N", assuming it stands for Yes and No coding with character values is one of the things that can add a lot of work to code.&lt;/P&gt;
&lt;P&gt;If you use numeric values with 1 for 'Y' and 0 for 'N' then you find a large number of things can be done quite easily.&lt;/P&gt;
&lt;P&gt;"Any value of 1 (y)" if max(of &amp;lt;varaible list&amp;gt;) = 1&lt;/P&gt;
&lt;P&gt;"All of values the same"&amp;nbsp;&amp;nbsp; range(of &amp;lt;variable list&amp;gt;) =0&lt;/P&gt;
&lt;P&gt;"All values Y"&amp;nbsp; if sum(of &amp;lt;variable list&amp;gt;)= n(of &amp;lt;variable list&amp;gt;)&lt;/P&gt;
&lt;P&gt;"All values 0 (N)" max(of &amp;lt;variable list&amp;gt;)=0&lt;/P&gt;
&lt;P&gt;"Any difference"&amp;nbsp;&amp;nbsp; range(of &amp;lt;variable list&amp;gt;)=1&lt;/P&gt;
&lt;P&gt;"Any N"&amp;nbsp; min(of &amp;lt;variable list&amp;gt;) =0&lt;/P&gt;
&lt;P&gt;"How many Y"&amp;nbsp;&amp;nbsp; sum(of &amp;lt;variable list&amp;gt;)&lt;/P&gt;
&lt;P&gt;"Percent of 1"&amp;nbsp;&amp;nbsp;&amp;nbsp; mean(of &amp;lt;variable list&amp;gt;) (this will be a decimal version: .25 =25%)&lt;/P&gt;
&lt;P&gt;"Percent of 0"&amp;nbsp; 1- mean(of &amp;lt;variable list&amp;gt;)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And just because someone gives you a file with Y N is not a good excuse. SAS custom informats and formats can read the values into 1/0 and display "Yes" "No" or "True/False" or any desired text.&lt;/P&gt;
&lt;PRE&gt;proc format;
invalue YN (upcase)
'Y' =1
'N' =0
other = .;
value yn
1='Y'
0='N'
.=' '
;
value tf
1='True'
0='False'
.='NA'
;
run;

data example;
   informat v1-v3 yn.;
   input v1-v3;
datalines;
Y N N
y n N
Y y n
;

proc print data=example;
   format v1-v3 yn.;
run;
proc print data=example;
   format v1-v3 tf.;
run;

&lt;/PRE&gt;
&lt;P&gt;Notice that the UPCASE option on the invalue, creating an informat Yn. to read such automagically adjusts the case. The Other option means anything not the expected y or n gets assigned a missing value so this helps prevent garbage results later.&lt;/P&gt;</description>
    <pubDate>Sat, 03 Apr 2021 07:00:37 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-04-03T07:00:37Z</dc:date>
    <item>
      <title>Is there any function  to find the observation value across the variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-any-function-to-find-the-observation-value-across-the/m-p/731085#M227717</link>
      <description>How I can achieve this!&lt;BR /&gt;I have 3 variables , x1,x2,x3 . These variables contains either "Y" or "N". I need to create a 4 th variable x4.&lt;BR /&gt;If any of the x1,x2,x3 contains "Y" then x4="Y".</description>
      <pubDate>Fri, 02 Apr 2021 23:23:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-any-function-to-find-the-observation-value-across-the/m-p/731085#M227717</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2021-04-02T23:23:03Z</dc:date>
    </item>
    <item>
      <title>Re: Is there any function  to find the observation value across the variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-any-function-to-find-the-observation-value-across-the/m-p/731086#M227718</link>
      <description>&lt;P&gt;Using whichc() should work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  x='N';
  y='N';
  z='N';
  output;
  y='Y';
  output;
  stop;
run;

data want;
  set have;
  if whichc('Y',x,y,z)&amp;gt;0 then var='Y';
  else var='N';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Apr 2021 23:35:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-any-function-to-find-the-observation-value-across-the/m-p/731086#M227718</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-04-02T23:35:02Z</dc:date>
    </item>
    <item>
      <title>Re: Is there any function  to find the observation value across the variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-there-any-function-to-find-the-observation-value-across-the/m-p/731109#M227738</link>
      <description>&lt;P&gt;"Y" and "N", assuming it stands for Yes and No coding with character values is one of the things that can add a lot of work to code.&lt;/P&gt;
&lt;P&gt;If you use numeric values with 1 for 'Y' and 0 for 'N' then you find a large number of things can be done quite easily.&lt;/P&gt;
&lt;P&gt;"Any value of 1 (y)" if max(of &amp;lt;varaible list&amp;gt;) = 1&lt;/P&gt;
&lt;P&gt;"All of values the same"&amp;nbsp;&amp;nbsp; range(of &amp;lt;variable list&amp;gt;) =0&lt;/P&gt;
&lt;P&gt;"All values Y"&amp;nbsp; if sum(of &amp;lt;variable list&amp;gt;)= n(of &amp;lt;variable list&amp;gt;)&lt;/P&gt;
&lt;P&gt;"All values 0 (N)" max(of &amp;lt;variable list&amp;gt;)=0&lt;/P&gt;
&lt;P&gt;"Any difference"&amp;nbsp;&amp;nbsp; range(of &amp;lt;variable list&amp;gt;)=1&lt;/P&gt;
&lt;P&gt;"Any N"&amp;nbsp; min(of &amp;lt;variable list&amp;gt;) =0&lt;/P&gt;
&lt;P&gt;"How many Y"&amp;nbsp;&amp;nbsp; sum(of &amp;lt;variable list&amp;gt;)&lt;/P&gt;
&lt;P&gt;"Percent of 1"&amp;nbsp;&amp;nbsp;&amp;nbsp; mean(of &amp;lt;variable list&amp;gt;) (this will be a decimal version: .25 =25%)&lt;/P&gt;
&lt;P&gt;"Percent of 0"&amp;nbsp; 1- mean(of &amp;lt;variable list&amp;gt;)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And just because someone gives you a file with Y N is not a good excuse. SAS custom informats and formats can read the values into 1/0 and display "Yes" "No" or "True/False" or any desired text.&lt;/P&gt;
&lt;PRE&gt;proc format;
invalue YN (upcase)
'Y' =1
'N' =0
other = .;
value yn
1='Y'
0='N'
.=' '
;
value tf
1='True'
0='False'
.='NA'
;
run;

data example;
   informat v1-v3 yn.;
   input v1-v3;
datalines;
Y N N
y n N
Y y n
;

proc print data=example;
   format v1-v3 yn.;
run;
proc print data=example;
   format v1-v3 tf.;
run;

&lt;/PRE&gt;
&lt;P&gt;Notice that the UPCASE option on the invalue, creating an informat Yn. to read such automagically adjusts the case. The Other option means anything not the expected y or n gets assigned a missing value so this helps prevent garbage results later.&lt;/P&gt;</description>
      <pubDate>Sat, 03 Apr 2021 07:00:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-there-any-function-to-find-the-observation-value-across-the/m-p/731109#M227738</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-04-03T07:00:37Z</dc:date>
    </item>
  </channel>
</rss>

