<?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: Using an array to recode a variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-an-array-to-recode-a-variable/m-p/706182#M216718</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I used one array to recode my 9 to "Missing" (.) I just did the array statment then did a Do loop where it says If 9 then .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But how would I use the array to recode my 2 to 0 while still formatting out as "Yes" in the output?&lt;/P&gt;</description>
    <pubDate>Wed, 16 Dec 2020 01:00:10 GMT</pubDate>
    <dc:creator>shortyofhb</dc:creator>
    <dc:date>2020-12-16T01:00:10Z</dc:date>
    <item>
      <title>Using an array to recode a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-an-array-to-recode-a-variable/m-p/706145#M216706</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a question in regards to using an array to recode what a variable codes for.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 10 variables (Q1-Q10). I have a proc format making it so 1="No" and 2="Yes" but am instructed to use an array to change 2="Yes" to 0="Yes" does anyone have tips on how to do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Should I make an array to say everytime there is a 2 to change it to a 0, and then add that 0="Yes" in the proc format? Or is there a more direct way to do this?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Tue, 15 Dec 2020 22:36:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-an-array-to-recode-a-variable/m-p/706145#M216706</guid>
      <dc:creator>shortyofhb</dc:creator>
      <dc:date>2020-12-15T22:36:56Z</dc:date>
    </item>
    <item>
      <title>Re: Using an array to recode a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-an-array-to-recode-a-variable/m-p/706167#M216712</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/360880"&gt;@shortyofhb&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a question in regards to using an array to recode what a variable codes for.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have 10 variables (Q1-Q10). I have a proc format making it so 1="No" and 2="Yes" but am instructed to use an array to change 2="Yes" to 0="Yes" does anyone have tips on how to do this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Should I make an array to say everytime there is a 2 to change it to a 0, and then add that 0="Yes" in the proc format? Or is there a more direct way to do this?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Sounds like a plan. The array is likely the shortest code to change to change the values.&lt;/P&gt;
&lt;P&gt;The format would have to be changed if you intend to use it with the recoded values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My personal approach would be an INFORMAT used to read the data as needed but that may be jumping ahead of an instructor.&lt;/P&gt;
&lt;P&gt;I am going to guess that the reason is so "Yes" sorts before "No" at some point.&lt;/P&gt;
&lt;P&gt;Personally Yes=1 and No=0 make more sense because 1) sum of the variable is number of yes responses, 2) mean of the variable is the percent of values entered as "yes" in decimal form: .125 is 12.5%.&amp;nbsp; But perhaps "No" is more important for this project.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Dec 2020 00:10:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-an-array-to-recode-a-variable/m-p/706167#M216712</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-12-16T00:10:18Z</dc:date>
    </item>
    <item>
      <title>Re: Using an array to recode a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-an-array-to-recode-a-variable/m-p/706176#M216716</link>
      <description>&lt;P&gt;Here's a tutorial on using Arrays in SAS&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/seminars/sas-arrays/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/seminars/sas-arrays/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One of the examples is pretty close to what you're looking for. Another paper that would be helpful for you to read is "Proc Format: Not Just Another Pretty Face" that lays out formats and how to recode variables with formats.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/360880"&gt;@shortyofhb&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a question in regards to using an array to recode what a variable codes for.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have 10 variables (Q1-Q10). I have a proc format making it so 1="No" and 2="Yes" but am instructed to use an array to change 2="Yes" to 0="Yes" does anyone have tips on how to do this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Should I make an array to say everytime there is a 2 to change it to a 0, and then add that 0="Yes" in the proc format? Or is there a more direct way to do this?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Dec 2020 00:39:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-an-array-to-recode-a-variable/m-p/706176#M216716</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-12-16T00:39:43Z</dc:date>
    </item>
    <item>
      <title>Re: Using an array to recode a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-an-array-to-recode-a-variable/m-p/706180#M216717</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thank you for the response. I would use an informat statement but the instructions we are learning says to use an array to change the code. Is there a general way to do this, or do you need to see my code?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using an external excel dataset that I imported in.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Dec 2020 00:55:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-an-array-to-recode-a-variable/m-p/706180#M216717</guid>
      <dc:creator>shortyofhb</dc:creator>
      <dc:date>2020-12-16T00:55:33Z</dc:date>
    </item>
    <item>
      <title>Re: Using an array to recode a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-an-array-to-recode-a-variable/m-p/706182#M216718</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I used one array to recode my 9 to "Missing" (.) I just did the array statment then did a Do loop where it says If 9 then .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But how would I use the array to recode my 2 to 0 while still formatting out as "Yes" in the output?&lt;/P&gt;</description>
      <pubDate>Wed, 16 Dec 2020 01:00:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-an-array-to-recode-a-variable/m-p/706182#M216718</guid>
      <dc:creator>shortyofhb</dc:creator>
      <dc:date>2020-12-16T01:00:10Z</dc:date>
    </item>
    <item>
      <title>Re: Using an array to recode a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-an-array-to-recode-a-variable/m-p/706200#M216726</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/360880"&gt;@shortyofhb&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;But how would I use the array to recode my 2 to 0 while still formatting out as "Yes" in the output?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You don't, those are two different things. So you need to take two different actions to make them both happen. Recoding the variable is a change the values stored in the variable. Similar to your change of the values from 9 to missing.&lt;/P&gt;
&lt;P&gt;But changing what is printed for that value is making a change to the format that is attached to the variable.&amp;nbsp; For that part you have two choices.&amp;nbsp; Make a new format with the same name as was used before and leave the same format attached to the variables. Or you could make a new format with a NEW name and attach that format to the variables.&amp;nbsp; The second probably preferred as it will cause less confusion.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Dec 2020 03:27:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-an-array-to-recode-a-variable/m-p/706200#M216726</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-12-16T03:27:47Z</dc:date>
    </item>
    <item>
      <title>Re: Using an array to recode a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-an-array-to-recode-a-variable/m-p/706216#M216734</link>
      <description>&lt;P&gt;Oh okay I think I see what you are saying.&lt;/P&gt;&lt;P&gt;So then I have one array that recodes my 9's to .'s.&lt;/P&gt;&lt;P&gt;I will have a second array that recodes all my 2's to 0's.&lt;/P&gt;&lt;P&gt;I will use a new value statement in my proc format to now tell SAS that 0=Yes right? And then attach this value to the variable I recoded?&lt;/P&gt;&lt;P&gt;Or am I interpreting this wrong? Do I remove the previous format from that was one the variables before this new one?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I currently have a proc format.&lt;/P&gt;&lt;P&gt;My variables&lt;/P&gt;&lt;P&gt;Then a format option to tell SAS what I want the variable to code for.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Dec 2020 05:44:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-an-array-to-recode-a-variable/m-p/706216#M216734</guid>
      <dc:creator>shortyofhb</dc:creator>
      <dc:date>2020-12-16T05:44:57Z</dc:date>
    </item>
    <item>
      <title>Re: Using an array to recode a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-an-array-to-recode-a-variable/m-p/706293#M216765</link>
      <description>&lt;P&gt;Sounds right.&amp;nbsp; Note that you should be able to recode 9 to missing and 0 to 2 inside the same DO loop that is looping over the same array.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Dec 2020 13:13:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-an-array-to-recode-a-variable/m-p/706293#M216765</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-12-16T13:13:08Z</dc:date>
    </item>
    <item>
      <title>Re: Using an array to recode a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-an-array-to-recode-a-variable/m-p/706377#M216805</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/360880"&gt;@shortyofhb&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do I remove the previous format from that was one the variables before this new one?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The choice between modifying your existing format or creating another format can be situational.&lt;/P&gt;
&lt;P&gt;Consider that the same format can be applied to many variables, as you apparently are doing now.&lt;/P&gt;
&lt;P&gt;Suppose another question, Say Q25 is currently using the same format for the 2/1 values but for some reason is &lt;STRONG&gt;not &lt;/STRONG&gt;re-coded for some reason. If you replace or modify the existing format to only use 0/1 values then Q25 is now missing a code for its 2 value. So you might either modify your existing format to include both 0 and 2 as "Yes" along with the 1 for "No" to allow continued use of the same format for Q1 - Q10 and Q25. Or you could create a new format that only uses the 0/1 coding for Yes/No.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you use the approach of coding both 0 and 2 to "Yes" you may get questions about appearance order for different variables though.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a very small example of similar formats applied to data somewhat like what you are discussing.&lt;/P&gt;
&lt;PRE&gt;proc format;
value yn
0 ='Yes'
1 ='No'
;
value yny
0,2 ='Yes'
1 ='No'
;
value ny
2 ='Yes'
1 ='No'
;
run;

data example;
   input v1 - v4;
datalines;
1 1 1 1
0 2 2 2
1 0 0 1
;

proc freq data=example;
  tables v1 - v4;
  format v1 yn. v2 yny. v3 ny. v4 yny.;
run;

&lt;/PRE&gt;
&lt;P&gt;Note the behavior of the values for V2 and V3 with the same values but different formats. And V2 and V4 with the same format but different values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you get to make some choices about new/replaced formats. Depending on actual use there may not be a single correct answer.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Dec 2020 17:25:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-an-array-to-recode-a-variable/m-p/706377#M216805</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-12-16T17:25:54Z</dc:date>
    </item>
  </channel>
</rss>

