<?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: Conditional statement looking up values from a different dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Conditional-statement-looking-up-values-from-a-different-dataset/m-p/443055#M110821</link>
    <description>&lt;P&gt;Try PROC SQL Cartesian product with where clause to exclude the records you don't need.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
DATA value;
input band min max;
datalines ;
1 0 100
2 101 200
3 201 300
4 301 400
5 401 501
6 501 600
7 601 700
8 701 800
9 801 900
;
DATA HAVE;
INPUT Business $ value;
datalines ;
A 50
B 70
C 360
D 780
E 356
F 126
G 800
H 200
I 150
;
RUN;

PROC SQL;
CREATE TABLE WANT AS
SELECT Business,Value,Band
FROM HAVE,VALUE
WHERE VALUE&amp;gt;MIN AND VALUE&amp;lt;=MAX;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 06 Mar 2018 21:19:12 GMT</pubDate>
    <dc:creator>SuryaKiran</dc:creator>
    <dc:date>2018-03-06T21:19:12Z</dc:date>
    <item>
      <title>Conditional statement looking up values from a different dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-statement-looking-up-values-from-a-different-dataset/m-p/442960#M110789</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please excuse me if I don't explain this very well, I will do my best to outline what I'm after.&lt;/P&gt;&lt;P&gt;I have 2 datasets in SAS that look like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="pic1.PNG" style="width: 224px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/19010iCC529518C937F14D/image-size/large?v=v2&amp;amp;px=999" role="button" title="pic1.PNG" alt="pic1.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;2)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PIC2.PNG" style="width: 166px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/19007i642716D231C7E8C3/image-size/large?v=v2&amp;amp;px=999" role="button" title="PIC2.PNG" alt="PIC2.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I would like a final dataset that takes dataset 2 and assigns it a band based on the min-max spread depicted by dataset 1, something that looks like the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="pic3.PNG" style="width: 230px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/19008iFED16B0C1BDA4639/image-size/large?v=v2&amp;amp;px=999" role="button" title="pic3.PNG" alt="pic3.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Any help is much appreciated! I had thought about somehow forcing a one to many merge, where every business in dataset 2 was duplicated by the amount of bands, then simply running if minvalue&amp;lt;value&amp;lt;=maxvalue then dummyvariable="YES", then getting rid of any rows that aren't "YES".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks,&lt;/P&gt;&lt;P&gt;Declan&lt;/P&gt;</description>
      <pubDate>Tue, 06 Mar 2018 16:50:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-statement-looking-up-values-from-a-different-dataset/m-p/442960#M110789</guid>
      <dc:creator>DeclanBall</dc:creator>
      <dc:date>2018-03-06T16:50:09Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional statement looking up values from a different dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-statement-looking-up-values-from-a-different-dataset/m-p/442966#M110790</link>
      <description>&lt;P&gt;There are a few approaches ... here's just one.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The first data set is easy to transform into a format:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data form;&lt;/P&gt;
&lt;P&gt;set dataset1;&lt;/P&gt;
&lt;P&gt;fmtname = 'bandcat';&lt;/P&gt;
&lt;P&gt;rename band=label min_value=start max_value=end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;proc format cntlin=form;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once you have the format, you can apply it anywhere a format is legal.&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set dataset2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if (0 &amp;lt;= value &amp;lt;= 900) then band = put(value, bandcat.);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That would create BAND as a character variable.&amp;nbsp; If&amp;nbsp;you want it as numeric, it takes a slightly more complex formula:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if (0 &amp;lt;= value &amp;lt;= 900) then band = input(put(value, bandcat.), 1.);&lt;/P&gt;</description>
      <pubDate>Tue, 06 Mar 2018 17:03:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-statement-looking-up-values-from-a-different-dataset/m-p/442966#M110790</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-03-06T17:03:02Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional statement looking up values from a different dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-statement-looking-up-values-from-a-different-dataset/m-p/443033#M110812</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/181682"&gt;@DeclanBall&lt;/a&gt;&amp;nbsp;if it is sets of 100's, math is fun:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input business $ value;
datalines;
A 50
B 70
C 360
D 780
E 356
F 126
G 800
H 200
I 150
;


data want;
set have;
if mod(value,100)=0 then Band=int(divide(value,100));
else Band=int(divide(value,100))+1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Mar 2018 20:33:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-statement-looking-up-values-from-a-different-dataset/m-p/443033#M110812</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-03-06T20:33:50Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional statement looking up values from a different dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-statement-looking-up-values-from-a-different-dataset/m-p/443055#M110821</link>
      <description>&lt;P&gt;Try PROC SQL Cartesian product with where clause to exclude the records you don't need.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
DATA value;
input band min max;
datalines ;
1 0 100
2 101 200
3 201 300
4 301 400
5 401 501
6 501 600
7 601 700
8 701 800
9 801 900
;
DATA HAVE;
INPUT Business $ value;
datalines ;
A 50
B 70
C 360
D 780
E 356
F 126
G 800
H 200
I 150
;
RUN;

PROC SQL;
CREATE TABLE WANT AS
SELECT Business,Value,Band
FROM HAVE,VALUE
WHERE VALUE&amp;gt;MIN AND VALUE&amp;lt;=MAX;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Mar 2018 21:19:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-statement-looking-up-values-from-a-different-dataset/m-p/443055#M110821</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-03-06T21:19:12Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional statement looking up values from a different dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-statement-looking-up-values-from-a-different-dataset/m-p/443318#M110898</link>
      <description>this worked like magic! Never thought to use formats in that way, many thanks</description>
      <pubDate>Wed, 07 Mar 2018 14:35:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-statement-looking-up-values-from-a-different-dataset/m-p/443318#M110898</guid>
      <dc:creator>DeclanBall</dc:creator>
      <dc:date>2018-03-07T14:35:18Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional statement looking up values from a different dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-statement-looking-up-values-from-a-different-dataset/m-p/443319#M110899</link>
      <description>They unfortunately weren't equal increments, apologies for the example dataset being misleading, thank you for your help though</description>
      <pubDate>Wed, 07 Mar 2018 14:36:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-statement-looking-up-values-from-a-different-dataset/m-p/443319#M110899</guid>
      <dc:creator>DeclanBall</dc:creator>
      <dc:date>2018-03-07T14:36:28Z</dc:date>
    </item>
  </channel>
</rss>

