<?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 get scores based on age group and gender between 2 datasets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/get-scores-based-on-age-group-and-gender-between-2-datasets/m-p/641537#M191211</link>
    <description>&lt;P&gt;I have 2 datasets -input1 and input2. Input1 contains scores based on id, age and sex and input2 contains grouping on age and scoret based age and gender. i need to scoret from input2 based on score, age and gender.&lt;/P&gt;
&lt;PRE&gt;data INPUT1;
  infile datalines dsd truncover;
  input id:BEST12. score:BEST12. sex:$1. age:BEST12.;
datalines4;
1001,240,M,11
1001,239,M,11
1002,238,M,13
1002,237,M,13
1003,216,F,17
1003,215,F,17
1003,214,F,17
1003,217,F,17
;;;;
&lt;/PRE&gt;
&lt;PRE&gt;data INPUT2;
  infile datalines dsd truncover;
  input graw:BEST12. gtscore:BEST12. age:$5. sex:$1.;
datalines4;
240,91,11-14,M
239,90,11-14,M
238,90,11-14,M
237,90,11-14,M
236,89,11-14,M
235,89,11-14,M
234,88,11-14,M
233,88,15-18,M
232,88,15-18,M
231,87,15-18,M
230,87,15-18,M
229,87,15-18,M
228,86,15-18,M
227,86,15-18,M
226,85,15-18,M
225,85,15-18,M
224,85,11-14,F
223,84,11-14,F
222,84,11-14,F
221,84,11-14,F
220,83,11-14,F
219,83,11-14,F
218,82,11-14,F
217,82,15-18,F
216,82,15-18,F
215,81,15-18,F
214,81,15-18,F
;;;;
&lt;/PRE&gt;
&lt;P&gt;i want the both to get the below result&lt;/P&gt;
&lt;PRE&gt;data RESULT;
  infile datalines dsd truncover;
  input id:BEST12. score:BEST12. sex:$1. age:BEST12. score_t:BEST12.;
datalines4;
1001,240,M,11,91
1001,239,M,11,90
1002,238,M,13,90
1002,237,M,13,90
1003,216,F,17,82
1003,215,F,17,81
1003,214,F,17,81
1003,217,F,17,82
;;;;
&lt;/PRE&gt;
&lt;P&gt;Any help on how to do the above&lt;/P&gt;</description>
    <pubDate>Tue, 21 Apr 2020 07:37:16 GMT</pubDate>
    <dc:creator>noda6003</dc:creator>
    <dc:date>2020-04-21T07:37:16Z</dc:date>
    <item>
      <title>get scores based on age group and gender between 2 datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-scores-based-on-age-group-and-gender-between-2-datasets/m-p/641537#M191211</link>
      <description>&lt;P&gt;I have 2 datasets -input1 and input2. Input1 contains scores based on id, age and sex and input2 contains grouping on age and scoret based age and gender. i need to scoret from input2 based on score, age and gender.&lt;/P&gt;
&lt;PRE&gt;data INPUT1;
  infile datalines dsd truncover;
  input id:BEST12. score:BEST12. sex:$1. age:BEST12.;
datalines4;
1001,240,M,11
1001,239,M,11
1002,238,M,13
1002,237,M,13
1003,216,F,17
1003,215,F,17
1003,214,F,17
1003,217,F,17
;;;;
&lt;/PRE&gt;
&lt;PRE&gt;data INPUT2;
  infile datalines dsd truncover;
  input graw:BEST12. gtscore:BEST12. age:$5. sex:$1.;
datalines4;
240,91,11-14,M
239,90,11-14,M
238,90,11-14,M
237,90,11-14,M
236,89,11-14,M
235,89,11-14,M
234,88,11-14,M
233,88,15-18,M
232,88,15-18,M
231,87,15-18,M
230,87,15-18,M
229,87,15-18,M
228,86,15-18,M
227,86,15-18,M
226,85,15-18,M
225,85,15-18,M
224,85,11-14,F
223,84,11-14,F
222,84,11-14,F
221,84,11-14,F
220,83,11-14,F
219,83,11-14,F
218,82,11-14,F
217,82,15-18,F
216,82,15-18,F
215,81,15-18,F
214,81,15-18,F
;;;;
&lt;/PRE&gt;
&lt;P&gt;i want the both to get the below result&lt;/P&gt;
&lt;PRE&gt;data RESULT;
  infile datalines dsd truncover;
  input id:BEST12. score:BEST12. sex:$1. age:BEST12. score_t:BEST12.;
datalines4;
1001,240,M,11,91
1001,239,M,11,90
1002,238,M,13,90
1002,237,M,13,90
1003,216,F,17,82
1003,215,F,17,81
1003,214,F,17,81
1003,217,F,17,82
;;;;
&lt;/PRE&gt;
&lt;P&gt;Any help on how to do the above&lt;/P&gt;</description>
      <pubDate>Tue, 21 Apr 2020 07:37:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-scores-based-on-age-group-and-gender-between-2-datasets/m-p/641537#M191211</guid>
      <dc:creator>noda6003</dc:creator>
      <dc:date>2020-04-21T07:37:16Z</dc:date>
    </item>
    <item>
      <title>Re: get scores based on age group and gender between 2 datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-scores-based-on-age-group-and-gender-between-2-datasets/m-p/641540#M191214</link>
      <description>&lt;P&gt;Create a format to convert age to age group, then use a hash object for your multiple keys:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
value agegroup
  11-14 = '11-14'
  15-18 = '15-18'
;
run;

data want;
set input1;
if _n_ = 1
then do;
  length
    agegroup $5
    score_t 8
  ;
  declare hash ag (dataset:"input2 (rename=(graw=score age=agegroup gtscore=score_t))");
  ag.definekey("agegroup","sex","score");
  ag.definedata("score_t");
  ag.definedone();
end;
agegroup = put(age,agegroup.);
if ag.find() ne 0 then score_t = .;
run;&lt;/CODE&gt;&lt;/PRE&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/240711"&gt;@noda6003&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have 2 datasets -input1 and input2. Input1 contains scores based on id, age and sex and input2 contains grouping on age and scoret based age and gender. i need to scoret from input2 based on score, age and gender.&lt;/P&gt;
&lt;PRE&gt;data INPUT1;
  infile datalines dsd truncover;
  input id:BEST12. score:BEST12. sex:$1. age:BEST12.;
datalines4;
1001,240,M,11
1001,239,M,11
1002,238,M,13
1002,237,M,13
1003,216,F,17
1003,215,F,17
1003,214,F,17
1003,217,F,17
;;;;
&lt;/PRE&gt;
&lt;PRE&gt;data INPUT2;
  infile datalines dsd truncover;
  input graw:BEST12. gtscore:BEST12. age:$5. sex:$1.;
datalines4;
240,91,11-14,M
239,90,11-14,M
238,90,11-14,M
237,90,11-14,M
236,89,11-14,M
235,89,11-14,M
234,88,11-14,M
233,88,15-18,M
232,88,15-18,M
231,87,15-18,M
230,87,15-18,M
229,87,15-18,M
228,86,15-18,M
227,86,15-18,M
226,85,15-18,M
225,85,15-18,M
224,85,11-14,F
223,84,11-14,F
222,84,11-14,F
221,84,11-14,F
220,83,11-14,F
219,83,11-14,F
218,82,11-14,F
217,82,15-18,F
216,82,15-18,F
215,81,15-18,F
214,81,15-18,F
;;;;
&lt;/PRE&gt;
&lt;P&gt;i want the both to get the below result&lt;/P&gt;
&lt;PRE&gt;data RESULT;
  infile datalines dsd truncover;
  input id:BEST12. score:BEST12. sex:$1. age:BEST12. score_t:BEST12.;
datalines4;
1001,240,M,11,91
1001,239,M,11,90
1002,238,M,13,90
1002,237,M,13,90
1003,216,F,17,82
1003,215,F,17,81
1003,214,F,17,81
1003,217,F,17,82
;;;;
&lt;/PRE&gt;
&lt;P&gt;Any help on how to do the above&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Apr 2020 08:08:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-scores-based-on-age-group-and-gender-between-2-datasets/m-p/641540#M191214</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-21T08:08:11Z</dc:date>
    </item>
    <item>
      <title>Re: get scores based on age group and gender between 2 datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-scores-based-on-age-group-and-gender-between-2-datasets/m-p/641541#M191215</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe a simple SQL left join?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data INPUT2V / view = INPUT2V;
  set INPUT2;
  start = input(scan(age,1,"-"),best.);
  end   = input(scan(age,2,"-"),best.);
run;

ods html;
proc sql;
create table WANT as
select a.*, b.gtscore as score_t
from
  INPUT1 as a
  left join
  INPUT2V as b
  on 
  a.score = b.graw
  and a.sex = b.sex
  and a.age between b.start and b.end
  order by a.id, a.score desc, a.sex, a.age
  ;
quit;
proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Tue, 21 Apr 2020 08:19:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-scores-based-on-age-group-and-gender-between-2-datasets/m-p/641541#M191215</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-04-21T08:19:18Z</dc:date>
    </item>
  </channel>
</rss>

