<?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: Create new variables based on a look up table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variables-based-on-a-look-up-table/m-p/69859#M15129</link>
    <description>Yes, PROC FORMAT (using CNTLIN=) would work creating a numeric format for your age range (START and END variables) and the LABEL variable will be a character string with your "match condition" values. When you find a match using the PUT function in a DATA step, you will want to use the INPUT function and the SCAN function to parse the LABEL (returned by the PUT function) and convert the sub-fields to numeric.&lt;BR /&gt;
&lt;BR /&gt;
Have a look at the SAS support  &lt;A href="http://support.sas.com/" target="_blank"&gt;http://support.sas.com/&lt;/A&gt;  website and search on phrase "PROC FORMAT" and include the CNTLIN keyword -- you prepare a SAS file with specific-named SAS variables (FMTNAME, START, END, HLO, LABEL) and pass the file to PROC FORMAT using CNTLIN=&lt;SASFILE&gt;, which generates the format from your "quote table" data.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;/SASFILE&gt;</description>
    <pubDate>Tue, 08 Sep 2009 01:59:08 GMT</pubDate>
    <dc:creator>sbb</dc:creator>
    <dc:date>2009-09-08T01:59:08Z</dc:date>
    <item>
      <title>Create new variables based on a look up table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variables-based-on-a-look-up-table/m-p/69858#M15128</link>
      <description>Hi there,&lt;BR /&gt;
&lt;BR /&gt;
I need to create a one line per customer file that creates 8 'monthly premium quote' variables based on a persons gender and age (we create quotes for smokers and non-smokers as well but we don't have this in our dataset).  So I have the data file that looks like:&lt;BR /&gt;
cust_num  age_yrs gender&lt;BR /&gt;
      1              33       F&lt;BR /&gt;
&lt;BR /&gt;
I also have a quote table that looks like this:&lt;BR /&gt;
&lt;BR /&gt;
Coverage   age_grp  female_ns female_s male_ns male_s&lt;BR /&gt;
100000        30-34        20.3         25.7       30.5       35.6&lt;BR /&gt;
200000        35-39        24.6         28.4       34.6       39.1&lt;BR /&gt;
&lt;BR /&gt;
I was wondering if there is a way to pull in my 'lookup table' and create the quotes I need.  I was thinking of transposing my look up table but then I still need to use it with my data to set up the new variables.  I was also thinking I might be able to do this with formats somehow?  Any advice would be greatly appreciated!&lt;BR /&gt;
&lt;BR /&gt;
Thanks,&lt;BR /&gt;
Christy</description>
      <pubDate>Mon, 07 Sep 2009 22:17:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variables-based-on-a-look-up-table/m-p/69858#M15128</guid>
      <dc:creator>christyh</dc:creator>
      <dc:date>2009-09-07T22:17:16Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variables based on a look up table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variables-based-on-a-look-up-table/m-p/69859#M15129</link>
      <description>Yes, PROC FORMAT (using CNTLIN=) would work creating a numeric format for your age range (START and END variables) and the LABEL variable will be a character string with your "match condition" values. When you find a match using the PUT function in a DATA step, you will want to use the INPUT function and the SCAN function to parse the LABEL (returned by the PUT function) and convert the sub-fields to numeric.&lt;BR /&gt;
&lt;BR /&gt;
Have a look at the SAS support  &lt;A href="http://support.sas.com/" target="_blank"&gt;http://support.sas.com/&lt;/A&gt;  website and search on phrase "PROC FORMAT" and include the CNTLIN keyword -- you prepare a SAS file with specific-named SAS variables (FMTNAME, START, END, HLO, LABEL) and pass the file to PROC FORMAT using CNTLIN=&lt;SASFILE&gt;, which generates the format from your "quote table" data.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;/SASFILE&gt;</description>
      <pubDate>Tue, 08 Sep 2009 01:59:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variables-based-on-a-look-up-table/m-p/69859#M15129</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-09-08T01:59:08Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variables based on a look up table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variables-based-on-a-look-up-table/m-p/69860#M15130</link>
      <description>Hi Scott,&lt;BR /&gt;
&lt;BR /&gt;
I'm just trying to get my data set up and I'm a bit confused... do I need to create a new variable with the match conditions and if so, how?&lt;BR /&gt;
&lt;BR /&gt;
I've used the proc format cntlin code before so I should be ok with that, its just getting my data ready.  Everything I've read is just setting up 1 condition, not multiple ones like I have...&lt;BR /&gt;
&lt;BR /&gt;
Thanks for any help,&lt;BR /&gt;
Christy</description>
      <pubDate>Fri, 11 Sep 2009 01:57:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variables-based-on-a-look-up-table/m-p/69860#M15130</guid>
      <dc:creator>christyh</dc:creator>
      <dc:date>2009-09-11T01:57:33Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variables based on a look up table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variables-based-on-a-look-up-table/m-p/69861#M15131</link>
      <description>As I mentioned, use the PUT function in an assignment statement to retrieve the results from your format, based on age range.  Code snippet shown below:&lt;BR /&gt;
&lt;BR /&gt;
length fmtdata $nnn ; /* max size to hold data returned from format / put */&lt;BR /&gt;
fmtdata = put(age,fmtname.);&lt;BR /&gt;
if fmtdata ne '?' then do;  /* test for OTHER='?'  condition */&lt;BR /&gt;
* code below presumes that the FORMAT RESULT variable is format with   ;&lt;BR /&gt;
* some number of sub-fields, separated by a blank, and using numeric       ;&lt;BR /&gt;
* length nnn when the format is generated.                                            ;&lt;BR /&gt;
f_s = input(scan(fmtdata,1,' '),nnn.);&lt;BR /&gt;
f_ns = input(scan(fmtdata,2,' '),nnn.);&lt;BR /&gt;
* ..etc..;&lt;BR /&gt;
* at this point you have numeric variables with quote info from format. ;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Fri, 11 Sep 2009 02:34:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variables-based-on-a-look-up-table/m-p/69861#M15131</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-09-11T02:34:18Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variables based on a look up table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variables-based-on-a-look-up-table/m-p/69862#M15132</link>
      <description>Thanks Scott,&lt;BR /&gt;
&lt;BR /&gt;
I guess I'm confused about even creating the format...  when I try to create it I'm getting an error:  ERROR: This range is repeated, or values overlap: 18-25.&lt;BR /&gt;
 because of the age range.&lt;BR /&gt;
&lt;BR /&gt;
This is the code I have:&lt;BR /&gt;
&lt;BR /&gt;
data ctrl;&lt;BR /&gt;
     set test_quotes (Rename=(age1=start age2=end)) end=last;&lt;BR /&gt;
      retain fmtname 'Quote' ;&lt;BR /&gt;
	 length start end 8;&lt;BR /&gt;
 &lt;BR /&gt;
     output;&lt;BR /&gt;
 &lt;BR /&gt;
     if last then do;&lt;BR /&gt;
      hlo='O';&lt;BR /&gt;
      label='***ERROR***';&lt;BR /&gt;
      output;&lt;BR /&gt;
   end;&lt;BR /&gt;
run;&lt;BR /&gt;
 &lt;BR /&gt;
proc format cntlin=ctrl;&lt;BR /&gt;
run;</description>
      <pubDate>Fri, 11 Sep 2009 04:34:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variables-based-on-a-look-up-table/m-p/69862#M15132</guid>
      <dc:creator>christyh</dc:creator>
      <dc:date>2009-09-11T04:34:32Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variables based on a look up table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variables-based-on-a-look-up-table/m-p/69863#M15133</link>
      <description>Did you debug the CNTLIN= data file to confirm the SAS error diagnostic being true?  That would be the first step.  Yes, the presumption is that you have discrete non-overlapping START and END values to populate your format.  Per the SAS documentation, this is a requirement, unless you are using other PROC FORMAT features beyond the scope of this post.  &lt;BR /&gt;
&lt;BR /&gt;
Also, your LENGTH statement is unnecessary - anyway, if it did matter for numeric variable granularity, it would need to be coded ahead of the SET statement, otherwise your input variables "could" be truncated, depending on the declared length.  Though not germaine to this post, regardless it's a SAS programming habit for you to consider.&lt;BR /&gt;
&lt;BR /&gt;
I suggest you analyze your input data, focusing on the critical variables FMTNAME, HLO, START and END.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Fri, 11 Sep 2009 16:02:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variables-based-on-a-look-up-table/m-p/69863#M15133</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-09-11T16:02:12Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variables based on a look up table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variables-based-on-a-look-up-table/m-p/69864#M15134</link>
      <description>Something like that?&lt;BR /&gt;
&lt;BR /&gt;
proc format;&lt;BR /&gt;
  value agegrp&lt;BR /&gt;
    30-34 ='30-34'&lt;BR /&gt;
    35-39 ='35-39'&lt;BR /&gt;
  ;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data customer;&lt;BR /&gt;
input cust_num age_yrs gender $;&lt;BR /&gt;
datalines;&lt;BR /&gt;
1 33 F&lt;BR /&gt;
;&lt;BR /&gt;
&lt;BR /&gt;
data quotes;&lt;BR /&gt;
input Coverage age_grp $ female_ns female_s male_ns male_s;&lt;BR /&gt;
datalines;&lt;BR /&gt;
100000 30-34 20.3 25.7 30.5 35.6&lt;BR /&gt;
200000 35-39 24.6 28.4 34.6 39.1&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
  select *&lt;BR /&gt;
    from customer left join quotes&lt;BR /&gt;
      on put(customer.age_yrs,agegrp.)=quotes.age_grp&lt;BR /&gt;
  ;&lt;BR /&gt;
quit;</description>
      <pubDate>Sat, 12 Sep 2009 11:39:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variables-based-on-a-look-up-table/m-p/69864#M15134</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2009-09-12T11:39:49Z</dc:date>
    </item>
  </channel>
</rss>

