<?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: Simplify the repeat format procedure? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Simplify-the-repeat-format-procedure/m-p/621572#M182726</link>
    <description>&lt;P&gt;Arrays are good for this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop = A B C);
 set test;
 array answers (*) A B C;
 array answers_flag (*) AA BB CC;
 do i = 1 to dim(answers); 
  if answers(i) in ('No', 'n') then answers_flag(i)=0;
  else if answers(i) in ('Yes', 'y') then answers_flag(i)=1;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 31 Jan 2020 22:56:02 GMT</pubDate>
    <dc:creator>SASKiwi</dc:creator>
    <dc:date>2020-01-31T22:56:02Z</dc:date>
    <item>
      <title>Simplify the repeat format procedure?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simplify-the-repeat-format-procedure/m-p/621569#M182724</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the follow repeat coding.&amp;nbsp; Any idea how to simply them?&amp;nbsp; Thanks.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop = A B C);
	set test;
	if A in ('No', 'n') then AA=0;
	if A in ('Yes', 'y') then AA=1;

	if B in ('No', 'n') then BB=0;
	if B in ('Yes', 'y') then BB=1;

	if C in ('No', 'n') then CC=0;
	if C in ('Yes', 'y') then CC=1;

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 31 Jan 2020 22:45:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simplify-the-repeat-format-procedure/m-p/621569#M182724</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2020-01-31T22:45:48Z</dc:date>
    </item>
    <item>
      <title>Re: Simplify the repeat format procedure?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simplify-the-repeat-format-procedure/m-p/621571#M182725</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data want;
 set test;
 array t a b c;
 array u  aa bb cc;
 do over t;
  if t in ('No', 'n') then u=0;
  else if t in ('Yes', 'y') then u=1;
 end;
 drop a b c;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Alternatively, you can use PROC Format aka User defined format/In-format as a look up.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 31 Jan 2020 22:54:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simplify-the-repeat-format-procedure/m-p/621571#M182725</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-01-31T22:54:47Z</dc:date>
    </item>
    <item>
      <title>Re: Simplify the repeat format procedure?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simplify-the-repeat-format-procedure/m-p/621572#M182726</link>
      <description>&lt;P&gt;Arrays are good for this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop = A B C);
 set test;
 array answers (*) A B C;
 array answers_flag (*) AA BB CC;
 do i = 1 to dim(answers); 
  if answers(i) in ('No', 'n') then answers_flag(i)=0;
  else if answers(i) in ('Yes', 'y') then answers_flag(i)=1;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 31 Jan 2020 22:56:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simplify-the-repeat-format-procedure/m-p/621572#M182726</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2020-01-31T22:56:02Z</dc:date>
    </item>
    <item>
      <title>Re: Simplify the repeat format procedure?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simplify-the-repeat-format-procedure/m-p/621573#M182727</link>
      <description>&lt;P&gt;Thank you so much for all of your wonderful help!&lt;/P&gt;</description>
      <pubDate>Fri, 31 Jan 2020 22:58:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simplify-the-repeat-format-procedure/m-p/621573#M182727</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2020-01-31T22:58:05Z</dc:date>
    </item>
    <item>
      <title>Re: Simplify the repeat format procedure?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Simplify-the-repeat-format-procedure/m-p/621580#M182732</link>
      <description>&lt;P&gt;For some of these things I prefer&amp;nbsp;informats.&lt;/P&gt;
&lt;PRE&gt;proc format library=work;
invalue myyesno (upcase)
'NO','N' = 0
'YES','Y' =1
' '=.
other= _error_;
run;

data example;
   infile datalines truncover;
   informat a myyesno.;
   input a;
datalines;
Y
y
Yes
YES
yEs
N
n
NO
no
nO

YN
3
;



&lt;/PRE&gt;
&lt;P&gt;Note the definition has (UPCASE). That means SAS will make the value uppercase before comparing to the key values. So if you have issues with humans entering data where the case may change as shown then you still get expected results. The explicit case of missing, ' ', allows the use of the other predicate to create warnings for invalid/unexpected data values as shown.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The informats can be used with an input statement if you already have the data read:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;AA = input(a,myyesno.);&lt;/P&gt;
&lt;P&gt;BB = input(b,myyesno.);&lt;/P&gt;
&lt;P&gt;CC = input(c,myyesno.);&lt;/P&gt;
&lt;P&gt;(or array). If there were 25 of these variables the array approach becomes very preferred.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that since the informat creates a numeric value there is no $ at the start of the informat name.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Feb 2020 17:22:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Simplify-the-repeat-format-procedure/m-p/621580#M182732</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-02-03T17:22:33Z</dc:date>
    </item>
  </channel>
</rss>

