<?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 insert a value into a dataset when use another dataset to define value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-insert-a-value-into-a-dataset-when-use-another-dataset-to/m-p/629231#M186042</link>
    <description>&lt;P&gt;Thanks for your solution ed_sas_member!&lt;/P&gt;</description>
    <pubDate>Tue, 03 Mar 2020 19:36:07 GMT</pubDate>
    <dc:creator>rengg0789</dc:creator>
    <dc:date>2020-03-03T19:36:07Z</dc:date>
    <item>
      <title>How to insert a value into a dataset when use another dataset to define value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-insert-a-value-into-a-dataset-when-use-another-dataset-to/m-p/629023#M185956</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hi fellow experts,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two datasets, called them dataset1 and dataset2. In dataset1, I have variables id, score, and grade. See below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;id&amp;nbsp; score&amp;nbsp; grade&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; 80&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; 76&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; 55&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, I have dataset2:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;low high grade&lt;/P&gt;&lt;P&gt;86&amp;nbsp; &amp;nbsp;100&amp;nbsp; A&lt;/P&gt;&lt;P&gt;71&amp;nbsp; &amp;nbsp;85&amp;nbsp; &amp;nbsp; B&lt;/P&gt;&lt;P&gt;60&amp;nbsp; &amp;nbsp;70&amp;nbsp; &amp;nbsp; C&lt;/P&gt;&lt;P&gt;0&amp;nbsp; &amp;nbsp; &amp;nbsp;59&amp;nbsp; &amp;nbsp; F&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I need to use score and dataset2 to determine the grade in the dataset 1. Anyone could help me write a code to do this? Thanks so much&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Mar 2020 05:20:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-insert-a-value-into-a-dataset-when-use-another-dataset-to/m-p/629023#M185956</guid>
      <dc:creator>rengg0789</dc:creator>
      <dc:date>2020-03-03T05:20:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to insert a value into a dataset when use another dataset to define value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-insert-a-value-into-a-dataset-when-use-another-dataset-to/m-p/629025#M185957</link>
      <description>&lt;P&gt;Please post the expected result, also posting data in usable form increases the number of useful answers.&lt;/P&gt;
&lt;P&gt;Idea to solve the problem: use dataset2 to create a format, use the put-function to translate the score to the appropriate grade.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dataset1;
   length id score 8 grade $ 1;
   infile datalines missover;
   input id score grade;
   datalines;
1 80 
2 76 
3 55 
;
run;

data dataset2;
   length low high 8 grade $ 1;
   input low high grade;
   datalines;
86   100  A
71   85    B
60   70    C
0     59    F
;
run;

data GradeFormat;
   set dataset2;

   length FmtName $ 32 Type HLO $ 1;
   retain FmtName "Score2Grade" Type "n" HLO "i";
   rename 
      low = start
      high = end
      grade = label
   ;
run;

proc format cntlin=GradeFormat;
run;

data want;
   set dataset1;
   grade = put(score, Score2Grade.);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 Mar 2020 06:00:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-insert-a-value-into-a-dataset-when-use-another-dataset-to/m-p/629025#M185957</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-03-03T06:00:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to insert a value into a dataset when use another dataset to define value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-insert-a-value-into-a-dataset-when-use-another-dataset-to/m-p/629080#M185988</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/314772"&gt;@rengg0789&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another approach to the one proposed by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp;and using a PROC FORMAT could be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dataset1;
	input id score;
	datalines;
1    80   
2    76
3    55
;

data dataset2;
	input low high grade $;
	datalines;
86   100   A
71   85    B
60   70    C
0    59    F
;
run;

proc sql;
	create table want as
	select a.id, a.score, b.grade
	from dataset1 as a inner join dataset2 as b
	on b.low &amp;lt;= a.score &amp;lt;= b.high;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Mar 2020 11:03:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-insert-a-value-into-a-dataset-when-use-another-dataset-to/m-p/629080#M185988</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-03-03T11:03:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to insert a value into a dataset when use another dataset to define value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-insert-a-value-into-a-dataset-when-use-another-dataset-to/m-p/629230#M186041</link>
      <description>&lt;P&gt;Thanks so much andreas_lds. This is really helpful to me.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Mar 2020 19:35:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-insert-a-value-into-a-dataset-when-use-another-dataset-to/m-p/629230#M186041</guid>
      <dc:creator>rengg0789</dc:creator>
      <dc:date>2020-03-03T19:35:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to insert a value into a dataset when use another dataset to define value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-insert-a-value-into-a-dataset-when-use-another-dataset-to/m-p/629231#M186042</link>
      <description>&lt;P&gt;Thanks for your solution ed_sas_member!&lt;/P&gt;</description>
      <pubDate>Tue, 03 Mar 2020 19:36:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-insert-a-value-into-a-dataset-when-use-another-dataset-to/m-p/629231#M186042</guid>
      <dc:creator>rengg0789</dc:creator>
      <dc:date>2020-03-03T19:36:07Z</dc:date>
    </item>
  </channel>
</rss>

