<?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: How to put obs in a range and merge in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-put-obs-in-a-range-and-merge/m-p/401997#M97581</link>
    <description>&lt;P&gt;There are a number of reasons that a Yes/No variable is often coded numerically as 1 or 0 for some types of analysis.&lt;/P&gt;
&lt;P&gt;The below code does that and shows creating a custom format to display text Yes/No.&lt;/P&gt;
&lt;PRE&gt;data have;
   input ID   Ky Kc;
   label
      Ky ='Kids yelled at me'
      KC ='Kids called me names'
   ;
datalines;
1     0    0
2     3    3
3     1    1
4     4    4
5     2    2
6     1    2
;
run;

Proc format library=work;
Value GroupYN
0="No"
1="Yes";
;
run;
data want;
   set have;
   Group = (max(ky,kc)&amp;gt;0);
   format Group GroupYN.; 
run;&lt;/PRE&gt;</description>
    <pubDate>Fri, 06 Oct 2017 22:41:59 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2017-10-06T22:41:59Z</dc:date>
    <item>
      <title>How to put obs in a range and merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-put-obs-in-a-range-and-merge/m-p/401908#M97538</link>
      <description>&lt;P&gt;Hello, I am a beginner SAS 9.4 user and I am trying to do a project for a study. In this study, I have two variables "Kids yelled at me" and "kids called me names" that constitute together to become bullying. The question was also answered on a scale of 0 to 4, o being no bullying and 1-4 being bullying so I would like first&amp;nbsp;like to assign new categories in each variable for those ranges and after that merge with the other variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp;Kids yelled at me&amp;nbsp; &amp;nbsp; Kids called me names&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4&lt;/P&gt;&lt;P&gt;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;so I would like in each category to keep 0 as no bullying and all the rest as bullying and after that merge both variables to get total bullying.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data want;&lt;BR /&gt;set work.main1;&lt;BR /&gt;if kids yelled at me=0 then group=No&lt;BR /&gt;if kids called me names=0 then group=No&lt;BR /&gt;if kids yelled at me=1 2 3 4 then group=yes;&lt;BR /&gt;if kids called me names=1 2 3 4 then group=yes;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc print data=want;&lt;BR /&gt;run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;This is where I am at, it is probably not correct&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Oct 2017 20:03:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-put-obs-in-a-range-and-merge/m-p/401908#M97538</guid>
      <dc:creator>diversitygal</dc:creator>
      <dc:date>2017-10-06T20:03:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to put obs in a range and merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-put-obs-in-a-range-and-merge/m-p/401919#M97543</link>
      <description>&lt;P&gt;Your code is really close actually. The fixes required include:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Change to using actual variable names rather than 'kids yelled at me'.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. For checking for multiple values use IN, ie if var1 in (1, 2, 3, 4)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. When assigning a value for a character variable it needs to be in quotes, ie group = "No";&lt;/P&gt;
&lt;P&gt;4. Semicolons are consistent&lt;/P&gt;
&lt;P&gt;5. You likely want IF/ELSE IF, not a bunch of IF statements.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you still get errors post back. Make sure to include your code and log.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Oct 2017 20:18:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-put-obs-in-a-range-and-merge/m-p/401919#M97543</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-06T20:18:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to put obs in a range and merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-put-obs-in-a-range-and-merge/m-p/401997#M97581</link>
      <description>&lt;P&gt;There are a number of reasons that a Yes/No variable is often coded numerically as 1 or 0 for some types of analysis.&lt;/P&gt;
&lt;P&gt;The below code does that and shows creating a custom format to display text Yes/No.&lt;/P&gt;
&lt;PRE&gt;data have;
   input ID   Ky Kc;
   label
      Ky ='Kids yelled at me'
      KC ='Kids called me names'
   ;
datalines;
1     0    0
2     3    3
3     1    1
4     4    4
5     2    2
6     1    2
;
run;

Proc format library=work;
Value GroupYN
0="No"
1="Yes";
;
run;
data want;
   set have;
   Group = (max(ky,kc)&amp;gt;0);
   format Group GroupYN.; 
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Oct 2017 22:41:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-put-obs-in-a-range-and-merge/m-p/401997#M97581</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-10-06T22:41:59Z</dc:date>
    </item>
  </channel>
</rss>

