<?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 a new variable based on value of an obs and name of a variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable-based-on-value-of-an-obs-and-name-of-a/m-p/544613#M150623</link>
    <description>Thank you! I've been browsing the communities for a while now, and usually can find the solution I need from past posts, but first time posting, it was much more efficient &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;It's just I'd love to find a tutorial that would give me an overview of primary useful functions, so I'd know what to search for when I need to use. For example, I knew of cats function but didn't know I could use it to concatenate a string constant with the numeric value of an observation, that's brilliant! I use concatenate function very effectively in Excel (and that's how I can automate writing tons of line of code in SAS, it just doesn't look good), so it'd be great if I can master these skills in SAS. Hopefully, over time, I guess.&lt;BR /&gt;Thank you again!</description>
    <pubDate>Wed, 20 Mar 2019 15:41:55 GMT</pubDate>
    <dc:creator>alann</dc:creator>
    <dc:date>2019-03-20T15:41:55Z</dc:date>
    <item>
      <title>Create a new variable based on value of an obs and name of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable-based-on-value-of-an-obs-and-name-of-a/m-p/544450#M150571</link>
      <description>&lt;P&gt;I am trying to create a new variable that will be equal to the value of another variable (i.e. any one of X1 through X10). However, which of the X variables it will be set equal to is stored in a separate variable (Near), where the suffixes are stored.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can actually do this simply with a bunch of if/then data steps. However, since I will probably repeat this for a number of different variables and there are 14 suffixes total, I'd love to find a way to automate it. Here's that simple code, and at the bottom is a sample from the data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for any help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data aaa1;&lt;BR /&gt;set aaa;&lt;BR /&gt;if near=1801 then las_trd_near=las_trd_1801;&lt;/P&gt;&lt;P&gt;if near=1802 then las_trd_near=las_trd_1802;&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;if near=1902 then las_trd_near=las_trd_1902;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data WORK.AAA;&lt;BR /&gt;infile datalines;&lt;BR /&gt;input LAS_TRD_1801:BEST12. LAS_TRD_1802:BEST12. LAS_TRD_1901:BEST12. near:32.;&lt;BR /&gt;datalines;&lt;BR /&gt;15 25 40 1801&lt;BR /&gt;75 26 45 1801&lt;BR /&gt;90 20 60 1802&lt;BR /&gt;50 30 70 1802&lt;BR /&gt;45 40 65 1803&lt;BR /&gt;;;;;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 06:35:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable-based-on-value-of-an-obs-and-name-of-a/m-p/544450#M150571</guid>
      <dc:creator>alann</dc:creator>
      <dc:date>2019-03-20T06:35:48Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new variable based on value of an obs and name of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable-based-on-value-of-an-obs-and-name-of-a/m-p/544454#M150573</link>
      <description>&lt;P&gt;You can do something like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WORK.AAA;
infile datalines;
input LAS_TRD_1801:BEST12. LAS_TRD_1802:BEST12. LAS_TRD_1901:BEST12. near:32.;
datalines;
15 25 40 1801
75 26 45 1801
90 20 60 1802
50 30 70 1802
45 40 65 1803
;;;;

data aaa1;
   set aaa;
   las_trd_near=input(vvaluex(cats('LAS_TRD_', near)), best12.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/267225"&gt;@alann&lt;/a&gt;,&amp;nbsp;please let me know if this works for you &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 07:54:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable-based-on-value-of-an-obs-and-name-of-a/m-p/544454#M150573</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-03-20T07:54:33Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new variable based on value of an obs and name of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable-based-on-value-of-an-obs-and-name-of-a/m-p/544512#M150598</link>
      <description>Thank you so much! It works beautifully.&lt;BR /&gt;I love the infinite capabilities of SAS, and hope to get more proficient with using all these different functions.</description>
      <pubDate>Wed, 20 Mar 2019 11:22:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable-based-on-value-of-an-obs-and-name-of-a/m-p/544512#M150598</guid>
      <dc:creator>alann</dc:creator>
      <dc:date>2019-03-20T11:22:53Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new variable based on value of an obs and name of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable-based-on-value-of-an-obs-and-name-of-a/m-p/544567#M150610</link>
      <description>&lt;P&gt;Glad to help &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Well, starting to browse the communities here, you've come a long way already.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Mar 2019 13:45:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable-based-on-value-of-an-obs-and-name-of-a/m-p/544567#M150610</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-03-20T13:45:10Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new variable based on value of an obs and name of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable-based-on-value-of-an-obs-and-name-of-a/m-p/544613#M150623</link>
      <description>Thank you! I've been browsing the communities for a while now, and usually can find the solution I need from past posts, but first time posting, it was much more efficient &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;It's just I'd love to find a tutorial that would give me an overview of primary useful functions, so I'd know what to search for when I need to use. For example, I knew of cats function but didn't know I could use it to concatenate a string constant with the numeric value of an observation, that's brilliant! I use concatenate function very effectively in Excel (and that's how I can automate writing tons of line of code in SAS, it just doesn't look good), so it'd be great if I can master these skills in SAS. Hopefully, over time, I guess.&lt;BR /&gt;Thank you again!</description>
      <pubDate>Wed, 20 Mar 2019 15:41:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-new-variable-based-on-value-of-an-obs-and-name-of-a/m-p/544613#M150623</guid>
      <dc:creator>alann</dc:creator>
      <dc:date>2019-03-20T15:41:55Z</dc:date>
    </item>
  </channel>
</rss>

