<?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: new variable-data dependent in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/new-variable-data-dependent/m-p/937291#M368283</link>
    <description>&lt;P&gt;Great, thanks!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My apology for late response, a lot of other things came up to be done in the meantime &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;Kind regards,&lt;/P&gt;
&lt;P&gt;Batta&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 26 Jul 2024 17:27:00 GMT</pubDate>
    <dc:creator>Batta</dc:creator>
    <dc:date>2024-07-26T17:27:00Z</dc:date>
    <item>
      <title>new variable-data dependent</title>
      <link>https://communities.sas.com/t5/SAS-Programming/new-variable-data-dependent/m-p/932742#M366916</link>
      <description>&lt;P&gt;Hi SAS expert,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My apology for not being able to better define the Subject. I’ll appreciate you help regarding the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a variable named InstanceName, that has the following values &lt;BR /&gt;Follow-up 01, &lt;BR /&gt;Follow-up 02,&lt;BR /&gt;Follow-up 03,&lt;BR /&gt;….&lt;BR /&gt;so I need to get another variable that will have (numerical) value 1 if InstanceName=Follow-01, value 2 if InstanceName=Follow-up 02, 3 if InastanceName=Follow-up 03 etc, and this is easy to do using proc sql, and conditional statement “case when … then … else…end” or SAS data statement...&lt;BR /&gt;The problem is that Folllow-up xx number is changing, and within different data sets might be up 4, while within other data sets might be 15 and up. &lt;BR /&gt;So is it possible to make this “case when… then… else end” statement more data dependent, so I don’t always have to check how may Follow-up xx are there for each set of data, and that SAS runs this up the last Follow-up xx available?&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Here how the code, in general, look like:&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table Table_1 as&lt;BR /&gt;select Var1, Var2, case &lt;BR /&gt;when InstanceName="Follow-up 01" then 1&lt;BR /&gt;when InstanceName="Follow-up 02" then 2&lt;BR /&gt;when InstanceName="Follow-up 03" then 3&lt;BR /&gt;….&lt;BR /&gt;else ...&lt;BR /&gt;end as FUP_NUM &lt;BR /&gt;from Data_1;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you very much for your time,&lt;BR /&gt;Batta&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jun 2024 20:18:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/new-variable-data-dependent/m-p/932742#M366916</guid>
      <dc:creator>Batta</dc:creator>
      <dc:date>2024-06-17T20:18:51Z</dc:date>
    </item>
    <item>
      <title>Re: new variable-data dependent</title>
      <link>https://communities.sas.com/t5/SAS-Programming/new-variable-data-dependent/m-p/932743#M366917</link>
      <description>&lt;P&gt;No Case/when needed:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;input(scan(Instance_name,2,' '),f2.) as Fup_num&lt;/PRE&gt;
&lt;P&gt;the Scan gets the part after the space and then Input reads it as a number.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/361111"&gt;@Batta&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi SAS expert,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My apology for not being able to better define the Subject. I’ll appreciate you help regarding the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a variable named InstanceName, that has the following values &lt;BR /&gt;Follow-up 01, &lt;BR /&gt;Follow-up 02,&lt;BR /&gt;Follow-up 03,&lt;BR /&gt;….&lt;BR /&gt;so I need to get another variable that will have (numerical) value 1 if InstanceName=Follow-01, value 2 if InstanceName=Follow-up 02, 3 if InastanceName=Follow-up 03 etc, and this is easy to do using proc sql, and conditional statement “case when … then … else…end” or SAS data statement...&lt;BR /&gt;The problem is that Folllow-up xx number is changing, and within different data sets might be up 4, while within other data sets might be 15 and up. &lt;BR /&gt;So is it possible to make this “case when… then… else end” statement more data dependent, so I don’t always have to check how may Follow-up xx are there for each set of data, and that SAS runs this up the last Follow-up xx available?&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Here how the code, in general, look like:&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table Table_1 as&lt;BR /&gt;select Var1, Var2, case &lt;BR /&gt;when InstanceName="Follow-up 01" then 1&lt;BR /&gt;when InstanceName="Follow-up 02" then 2&lt;BR /&gt;when InstanceName="Follow-up 03" then 3&lt;BR /&gt;….&lt;BR /&gt;else ...&lt;BR /&gt;end as FUP_NUM &lt;BR /&gt;from Data_1;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you very much for your time,&lt;BR /&gt;Batta&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jun 2024 20:29:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/new-variable-data-dependent/m-p/932743#M366917</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-06-17T20:29:44Z</dc:date>
    </item>
    <item>
      <title>Re: new variable-data dependent</title>
      <link>https://communities.sas.com/t5/SAS-Programming/new-variable-data-dependent/m-p/937291#M368283</link>
      <description>&lt;P&gt;Great, thanks!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My apology for late response, a lot of other things came up to be done in the meantime &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;Kind regards,&lt;/P&gt;
&lt;P&gt;Batta&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jul 2024 17:27:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/new-variable-data-dependent/m-p/937291#M368283</guid>
      <dc:creator>Batta</dc:creator>
      <dc:date>2024-07-26T17:27:00Z</dc:date>
    </item>
  </channel>
</rss>

