<?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 Convert a Ranged Lookup to Standard in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Convert-a-Ranged-Lookup-to-Standard/m-p/814305#M321422</link>
    <description>&lt;P&gt;I have a lookup being provided to me in the following format.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data test2;
input code1 $6. code2 $6. data;
datalines;
23145 23147 5
7892F 7892F 6
7893F 7893F 6
32012 32012 7
4456G 4456G 8
80090 80091 9
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have data structured like this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data test1;
input code $5.;
datalines;
80090
80091
7892F
7893F
7893F
32012
4456G
23145
23146
23147
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I had previously been trying to join data in the following way, which creates a cartesian join and I'm unable to execute on our large dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sql;
create table want as
     select a.*,
              b.data
     from test1 a left join test2 b on
           (a.code &amp;lt;= b.code2)
           And
           (a.code &amp;gt;= b.code1)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;To remedy this, I was trying to figure out a way to "flatten" this lookup so that I would have the following.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt; data want2;
input code1 $6. data;
datalines;
23145 5
23146 5
23147 5
7892F 6
7893F 6
32012 7
4456G 8
80090 9
80091 9
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Essentially trying to spell out all the values that would be in the ranges and create a unique line for each. How could I create want2? To my current knowledge, none of the lookup values that contain letters would have a range, i.e., the code1 and code2 values would match. But if there's a way to create a robust process that could account for future changes from this I would be very interested.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm also open to thoughts on how to optimize the join (create want directly), lookup or anyway to complete.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 19 May 2022 14:58:47 GMT</pubDate>
    <dc:creator>A_SAS_Man</dc:creator>
    <dc:date>2022-05-19T14:58:47Z</dc:date>
    <item>
      <title>Convert a Ranged Lookup to Standard</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-a-Ranged-Lookup-to-Standard/m-p/814305#M321422</link>
      <description>&lt;P&gt;I have a lookup being provided to me in the following format.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data test2;
input code1 $6. code2 $6. data;
datalines;
23145 23147 5
7892F 7892F 6
7893F 7893F 6
32012 32012 7
4456G 4456G 8
80090 80091 9
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have data structured like this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data test1;
input code $5.;
datalines;
80090
80091
7892F
7893F
7893F
32012
4456G
23145
23146
23147
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I had previously been trying to join data in the following way, which creates a cartesian join and I'm unable to execute on our large dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sql;
create table want as
     select a.*,
              b.data
     from test1 a left join test2 b on
           (a.code &amp;lt;= b.code2)
           And
           (a.code &amp;gt;= b.code1)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;To remedy this, I was trying to figure out a way to "flatten" this lookup so that I would have the following.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt; data want2;
input code1 $6. data;
datalines;
23145 5
23146 5
23147 5
7892F 6
7893F 6
32012 7
4456G 8
80090 9
80091 9
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Essentially trying to spell out all the values that would be in the ranges and create a unique line for each. How could I create want2? To my current knowledge, none of the lookup values that contain letters would have a range, i.e., the code1 and code2 values would match. But if there's a way to create a robust process that could account for future changes from this I would be very interested.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm also open to thoughts on how to optimize the join (create want directly), lookup or anyway to complete.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 May 2022 14:58:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-a-Ranged-Lookup-to-Standard/m-p/814305#M321422</guid>
      <dc:creator>A_SAS_Man</dc:creator>
      <dc:date>2022-05-19T14:58:47Z</dc:date>
    </item>
    <item>
      <title>Re: Convert a Ranged Lookup to Standard</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-a-Ranged-Lookup-to-Standard/m-p/814311#M321423</link>
      <description>&lt;P&gt;Consider using a format instead.&lt;/P&gt;
&lt;P&gt;Performance will be much faster but not sorted. If sort order is important, sort it after the fact.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test2;
input code1 $6. code2 $6. data;
datalines;
23145 23147 5
7892F 7892F 6
7893F 7893F 6
32012 32012 7
4456G 4456G 8
80090 80091 9
;

data code_fmt;
set test2;
fmtname = 'code_fmt';
type='C';
rename code1=start code2=end data=label;
run;

proc format cntlin=code_fmt;
run;


data test1;
input code $5.;
code_formatted = put(code, $code_fmt.);
datalines;
80090
80091
7892F
7893F
7893F
32012
4456G
23145
23146
23147
;
run;

proc print data=test1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/234586"&gt;@A_SAS_Man&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a lookup being provided to me in the following format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;data test2;
input code1 $6. code2 $6. data;
datalines;
23145 23147 5
7892F 7892F 6
7893F 7893F 6
32012 32012 7
4456G 4456G 8
80090 80091 9
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I have data structured like this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;data test1;
input code $5.;
datalines;
80090
80091
7892F
7893F
7893F
32012
4456G
23145
23146
23147
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I had previously been trying to join data in the following way, which creates a cartesian join and I'm unable to execute on our large dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;proc sql;
create table want as
     select a.*,
              b.data
     from test1 a left join test2 b on
           (a.code &amp;lt;= b.code2)
           And
           (a.code &amp;gt;= b.code1)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To remedy this, I was trying to figure out a way to "flatten" this lookup so that I would have the following.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt; data want2;
input code1 $6. data;
datalines;
23145 5
23146 5
23147 5
7892F 6
7893F 6
32012 7
4456G 8
80090 9
80091 9
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Essentially trying to spell out all the values that would be in the ranges and create a unique line for each. How could I create want2? To my current knowledge, none of the lookup values that contain letters would have a range, i.e., the code1 and code2 values would match. But if there's a way to create a robust process that could account for future changes from this I would be very interested.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm also open to thoughts on how to optimize the join (create want directly), lookup or anyway to complete.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 May 2022 15:34:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-a-Ranged-Lookup-to-Standard/m-p/814311#M321423</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-05-19T15:34:23Z</dc:date>
    </item>
    <item>
      <title>Re: Convert a Ranged Lookup to Standard</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-a-Ranged-Lookup-to-Standard/m-p/814327#M321429</link>
      <description>&lt;P&gt;Thanks this appears to be working, one question. If I had two data fields I was trying to attach as part of this would I essentially just have to repeat this process for each data element? Or is there a way to use format to attach two values? See example alternate test2 below, if I wanted to attach data2 a the same time and with the same logic as data is there a simple way to do that in your method? Essentially data2 in my process is just a description that I need on there.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data test2;
input code1 $6. code2 $6. data data2;
datalines;
23145 23147 5 k
7892F 7892F 6 l
7893F 7893F 6 l
32012 32012 7 y
4456G 4456G 8 f
80090 80091 9 s
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 May 2022 17:15:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-a-Ranged-Lookup-to-Standard/m-p/814327#M321429</guid>
      <dc:creator>A_SAS_Man</dc:creator>
      <dc:date>2022-05-19T17:15:19Z</dc:date>
    </item>
    <item>
      <title>Re: Convert a Ranged Lookup to Standard</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-a-Ranged-Lookup-to-Standard/m-p/814337#M321431</link>
      <description>You cannot add two items to a format, so you'd need to create multiple formats. &lt;BR /&gt;If you're doing two or three of these it's still efficient to use a format. &lt;BR /&gt;If you need to bring over more items then I'd use a hash lookup instead but I don't code hash tables.</description>
      <pubDate>Thu, 19 May 2022 17:19:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-a-Ranged-Lookup-to-Standard/m-p/814337#M321431</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-05-19T17:19:03Z</dc:date>
    </item>
    <item>
      <title>Re: Convert a Ranged Lookup to Standard</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-a-Ranged-Lookup-to-Standard/m-p/814356#M321432</link>
      <description>&lt;P&gt;You could also use a concatenation of&amp;nbsp;&lt;FONT face="courier new,courier"&gt;data&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;data2&lt;/FONT&gt;&amp;nbsp;(with a suitable delimiter) as the format label and then decompose the formatted value using the SCAN function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If &lt;FONT face="courier new,courier"&gt;data2&lt;/FONT&gt; depends on &lt;FONT face="courier new,courier"&gt;data&lt;/FONT&gt;, not on the codes, and the same (&lt;FONT face="courier new,courier"&gt;data&lt;/FONT&gt;, &lt;FONT face="courier new,courier"&gt;data2&lt;/FONT&gt;) pair applies to multiple ranges of codes, a separate look-up "&lt;FONT face="courier new,courier"&gt;data&lt;/FONT&gt; → &lt;FONT face="courier new,courier"&gt;data2&lt;/FONT&gt;" would avoid the need to store multiple copies of (possibly long) &lt;FONT face="courier new,courier"&gt;data2&lt;/FONT&gt; values in the format.&lt;/P&gt;</description>
      <pubDate>Thu, 19 May 2022 19:59:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-a-Ranged-Lookup-to-Standard/m-p/814356#M321432</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-05-19T19:59:18Z</dc:date>
    </item>
  </channel>
</rss>

