<?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: Sas Macro dynamic values and look up from another table in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sas-Macro-dynamic-values-and-look-up-from-another-table/m-p/911339#M359377</link>
    <description>&lt;P&gt;Your explanation is not clear.&amp;nbsp;Your dataset does not have variables VARNAME nor VAL.&amp;nbsp;Show working code for a simple example.&amp;nbsp; Then show a second example and explain what needs to change.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please show your data as a simple DATA step and not just a a listing.&amp;nbsp; That way we know the actual variable names, types and lengths.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input name :$32. age ;
cards;
Mike_1 5.0
Sar_2 6.5
Ste_3 8.0
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you just want to number the observations in your existing dataset then that is simple.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  var_name +1 ;
  set have;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1705029327791.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/92467i8E424F00458B14EA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1705029327791.png" alt="Tom_0-1705029327791.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the goal is to combine your existing dataset with some other dataset then just use a data step MERGE or perhaps PROC SQL.&amp;nbsp; But we need to know the variable names in the other dataset that you want to match to NAME so you can attach the value of AGE and call i VAL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as 
select a.*,b.age as VAL
from other_dataset a
left join have b
on a.var_name = b.name
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or perhaps you just want to create a numeric informat that will convert those NAME values into those AGE values.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
invalue age
'Mike_1'= 5.0
'Sar_2'= 6.5
'Ste_3'= 8.0
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So that you can then use that in another data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 set other;
  val = input(varname,age.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If so then convert the dataset into control dataset that you can feed into PROC FORMAT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 12 Jan 2024 03:25:37 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2024-01-12T03:25:37Z</dc:date>
    <item>
      <title>Sas Macro dynamic values and look up from another table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sas-Macro-dynamic-values-and-look-up-from-another-table/m-p/911335#M359376</link>
      <description>Hi. I have a dataset (dataset1) as follow (variable name and age). &lt;BR /&gt;Name Age&lt;BR /&gt;Mike_1 5.0&lt;BR /&gt;Sar_2 6.5&lt;BR /&gt;Ste_3 8.0&lt;BR /&gt;&lt;BR /&gt;I want to create a dataset that would take values from age &lt;BR /&gt;as the following:” from above dataset and modify my another dataset (dataset2):&lt;BR /&gt;Data dataset2_mod;&lt;BR /&gt;Set dataset2;&lt;BR /&gt;If var_name=1 (if variable name’s value has 1 as in Mike_1) then val=5.0;&lt;BR /&gt;If var_name=2 (sar_2 has 2) then val=6.5;&lt;BR /&gt;Etc.&lt;BR /&gt;Run; &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I want to modify dataset2 by sas macro parameter that would have …_1, …_2 first identify those (always would have 9 names from 1 to 9) but important the age variables’ values would change so that those should be a macro parameters. How can I do that? Thank you.</description>
      <pubDate>Fri, 12 Jan 2024 02:15:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sas-Macro-dynamic-values-and-look-up-from-another-table/m-p/911335#M359376</guid>
      <dc:creator>Emma2021</dc:creator>
      <dc:date>2024-01-12T02:15:16Z</dc:date>
    </item>
    <item>
      <title>Re: Sas Macro dynamic values and look up from another table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sas-Macro-dynamic-values-and-look-up-from-another-table/m-p/911339#M359377</link>
      <description>&lt;P&gt;Your explanation is not clear.&amp;nbsp;Your dataset does not have variables VARNAME nor VAL.&amp;nbsp;Show working code for a simple example.&amp;nbsp; Then show a second example and explain what needs to change.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please show your data as a simple DATA step and not just a a listing.&amp;nbsp; That way we know the actual variable names, types and lengths.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input name :$32. age ;
cards;
Mike_1 5.0
Sar_2 6.5
Ste_3 8.0
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you just want to number the observations in your existing dataset then that is simple.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  var_name +1 ;
  set have;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1705029327791.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/92467i8E424F00458B14EA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1705029327791.png" alt="Tom_0-1705029327791.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the goal is to combine your existing dataset with some other dataset then just use a data step MERGE or perhaps PROC SQL.&amp;nbsp; But we need to know the variable names in the other dataset that you want to match to NAME so you can attach the value of AGE and call i VAL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as 
select a.*,b.age as VAL
from other_dataset a
left join have b
on a.var_name = b.name
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or perhaps you just want to create a numeric informat that will convert those NAME values into those AGE values.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
invalue age
'Mike_1'= 5.0
'Sar_2'= 6.5
'Ste_3'= 8.0
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So that you can then use that in another data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 set other;
  val = input(varname,age.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If so then convert the dataset into control dataset that you can feed into PROC FORMAT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jan 2024 03:25:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sas-Macro-dynamic-values-and-look-up-from-another-table/m-p/911339#M359377</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-01-12T03:25:37Z</dc:date>
    </item>
    <item>
      <title>Re: Sas Macro dynamic values and look up from another table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sas-Macro-dynamic-values-and-look-up-from-another-table/m-p/911348#M359379</link>
      <description>&lt;P&gt;You don't show us how dataset2 looks like so below based on guessing hoping it will give you sufficient guidance to solve the problem with your real data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ds1;
  input var $ age;
  datalines;
Mike_1 5.0
Sar_2 6.5
Ste_3 8.0
;

data ds2;
  input var_name $;
  datalines;
2
3
1
4
;

data ds2_mod(drop=_:);
  if _n_=1 then
    do;
      length age 8;
      dcl hash h1();
      h1.defineKey('var_name');
      h1.defineData('age');
      h1.defineDone();
      do until(_done);
        set ds1(keep=var age rename=(var=_var)) end=_done;
        var_name=scan(_var,-1,'_');
        if h1.check() ne 0 then h1.add();
      end;
    end;

  set ds2;
  if h1.find() ne 0 then call missing(age);

run;

proc print data=ds2_mod;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1705033310370.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/92474i8D2F95D6A68F82FF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1705033310370.png" alt="Patrick_0-1705033310370.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jan 2024 04:22:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sas-Macro-dynamic-values-and-look-up-from-another-table/m-p/911348#M359379</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-01-12T04:22:23Z</dc:date>
    </item>
    <item>
      <title>Re: Sas Macro dynamic values and look up from another table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sas-Macro-dynamic-values-and-look-up-from-another-table/m-p/911371#M359391</link>
      <description>&lt;P&gt;Looks to me like a simple join on a substring:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;on scan(t1.name,2,"_") = t2.var_name&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Positively no macro coding needed.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jan 2024 11:06:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sas-Macro-dynamic-values-and-look-up-from-another-table/m-p/911371#M359391</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-01-12T11:06:55Z</dc:date>
    </item>
    <item>
      <title>Re: Sas Macro dynamic values and look up from another table</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sas-Macro-dynamic-values-and-look-up-from-another-table/m-p/911398#M359402</link>
      <description>Thank you-yes indeed -simple and would work too</description>
      <pubDate>Fri, 12 Jan 2024 16:20:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sas-Macro-dynamic-values-and-look-up-from-another-table/m-p/911398#M359402</guid>
      <dc:creator>Emma2021</dc:creator>
      <dc:date>2024-01-12T16:20:06Z</dc:date>
    </item>
  </channel>
</rss>

