<?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: Alternative to multiple if statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Alternative-to-multiple-if-statement/m-p/892558#M352522</link>
    <description>&lt;P&gt;So you want to apply TRANSACTIONS to and existing dataset?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That is what the UPDATE statement in SAS is designed for.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So first make your transaction dataset that has the KEY variable(s) and any values you want modified.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data trans;
  length id $2 dob 8;
  input id dob :yymmdd.;
  format dob yymmdd10.;
cards;
02 1948-03-21
03 1954-02-25
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then make sure both the OLD and the TRANS datasets are sorted by the KEY variable(s).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now you can use the UPDATE statement to apply the transactions to OLD and make a NEW dataset.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new;
  update old trans;
  by id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you have multiple variables that have transactions you can include those also.&amp;nbsp; Just put missing values for the variables that you don't want the transaction to change. (If you want to force a value to missing that is an advanced topic.)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data trans;
  length id $2 dob 8 gender $1;
  input id dob :yymmdd. gender;
  format dob yymmdd10.;
cards;
02 1948-03-21 .
03 1954-02-25 M
05 . F
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 04 Sep 2023 14:01:15 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-09-04T14:01:15Z</dc:date>
    <item>
      <title>Alternative to multiple if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Alternative-to-multiple-if-statement/m-p/892553#M352518</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to manually input date of births to ids like this for nearly 20 ids.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any alternative way to simplify this code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data test;&lt;/P&gt;&lt;P&gt;set old;&lt;/P&gt;&lt;P&gt;if id = "02" then do;&lt;/P&gt;&lt;P&gt;dob = input ('1948 - 03- 21', yymmdd10.) ;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;if id = "03" then do;&lt;/P&gt;&lt;P&gt;dob = input ('1954- 02- 25', yymmdd10.) ;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Sep 2023 13:25:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Alternative-to-multiple-if-statement/m-p/892553#M352518</guid>
      <dc:creator>nxmogil</dc:creator>
      <dc:date>2023-09-04T13:25:21Z</dc:date>
    </item>
    <item>
      <title>Re: Alternative to multiple if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Alternative-to-multiple-if-statement/m-p/892554#M352519</link>
      <description>&lt;P&gt;If there is no pattern, then you are stuck typing each dob.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could reduce the amount of typing&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if id = "02" then dob = '21MAR1948'd;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could also read the ID and DOB into SAS from a CARDS/DATALINES statement, or read them in from an external file, which would probably be even less typing.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Sep 2023 13:37:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Alternative-to-multiple-if-statement/m-p/892554#M352519</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-09-04T13:37:34Z</dc:date>
    </item>
    <item>
      <title>Re: Alternative to multiple if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Alternative-to-multiple-if-statement/m-p/892555#M352520</link>
      <description>Hi ,&lt;BR /&gt;Great thanks for the quick response. Actually i am updating a dataset for which few ids have DOB and for few of them missing. Thats the reason I am updationg DOBs for missing ids.</description>
      <pubDate>Mon, 04 Sep 2023 13:38:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Alternative-to-multiple-if-statement/m-p/892555#M352520</guid>
      <dc:creator>nxmogil</dc:creator>
      <dc:date>2023-09-04T13:38:43Z</dc:date>
    </item>
    <item>
      <title>Re: Alternative to multiple if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Alternative-to-multiple-if-statement/m-p/892558#M352522</link>
      <description>&lt;P&gt;So you want to apply TRANSACTIONS to and existing dataset?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That is what the UPDATE statement in SAS is designed for.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So first make your transaction dataset that has the KEY variable(s) and any values you want modified.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data trans;
  length id $2 dob 8;
  input id dob :yymmdd.;
  format dob yymmdd10.;
cards;
02 1948-03-21
03 1954-02-25
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then make sure both the OLD and the TRANS datasets are sorted by the KEY variable(s).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now you can use the UPDATE statement to apply the transactions to OLD and make a NEW dataset.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new;
  update old trans;
  by id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you have multiple variables that have transactions you can include those also.&amp;nbsp; Just put missing values for the variables that you don't want the transaction to change. (If you want to force a value to missing that is an advanced topic.)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data trans;
  length id $2 dob 8 gender $1;
  input id dob :yymmdd. gender;
  format dob yymmdd10.;
cards;
02 1948-03-21 .
03 1954-02-25 M
05 . F
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Sep 2023 14:01:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Alternative-to-multiple-if-statement/m-p/892558#M352522</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-09-04T14:01:15Z</dc:date>
    </item>
    <item>
      <title>Re: Alternative to multiple if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Alternative-to-multiple-if-statement/m-p/892567#M352525</link>
      <description>Hi Great thanks once again,&lt;BR /&gt;&lt;BR /&gt;in my old data set i have id gender, addm phone and many variables including this DOB. So in my trans dataset according to you can there be onlt two variables (ID, Dob) and can do update still&lt;BR /&gt;</description>
      <pubDate>Mon, 04 Sep 2023 15:00:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Alternative-to-multiple-if-statement/m-p/892567#M352525</guid>
      <dc:creator>nxmogil</dc:creator>
      <dc:date>2023-09-04T15:00:46Z</dc:date>
    </item>
    <item>
      <title>Re: Alternative to multiple if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Alternative-to-multiple-if-statement/m-p/892568#M352526</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/441935"&gt;@nxmogil&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Hi Great thanks once again,&lt;BR /&gt;&lt;BR /&gt;in my old data set i have id gender, addm phone and many variables including this DOB. So in my trans dataset according to you can there be onlt two variables (ID, Dob) and can do update still&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes.&amp;nbsp; The transaction dataset only needs the KEY variable(s) and whatever variables you want to make changes to.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Sep 2023 15:06:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Alternative-to-multiple-if-statement/m-p/892568#M352526</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-09-04T15:06:10Z</dc:date>
    </item>
    <item>
      <title>Re: Alternative to multiple if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Alternative-to-multiple-if-statement/m-p/892575#M352533</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/441935"&gt;@nxmogil&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Hi ,&lt;BR /&gt;Great thanks for the quick response. Actually i am updating a dataset for which few ids have DOB and for few of them missing. Thats the reason I am updationg DOBs for missing ids.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Hello &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/441935"&gt;@nxmogil&lt;/a&gt; , its always helpful if you explain the reasons you are doing something in your original message. You will get faster and better answers than simply posting code without the background reasons why you are doing something.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Sep 2023 15:19:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Alternative-to-multiple-if-statement/m-p/892575#M352533</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-09-04T15:19:00Z</dc:date>
    </item>
    <item>
      <title>Re: Alternative to multiple if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Alternative-to-multiple-if-statement/m-p/892576#M352534</link>
      <description>Thank you so much it worked for me</description>
      <pubDate>Mon, 04 Sep 2023 15:21:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Alternative-to-multiple-if-statement/m-p/892576#M352534</guid>
      <dc:creator>nxmogil</dc:creator>
      <dc:date>2023-09-04T15:21:44Z</dc:date>
    </item>
    <item>
      <title>Re: Alternative to multiple if statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Alternative-to-multiple-if-statement/m-p/892577#M352535</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/441935"&gt;@nxmogil&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Hi Great thanks once again,&lt;BR /&gt;&lt;BR /&gt;in my old data set i have id gender, addm phone and many variables including this DOB. So in my trans dataset according to you can there be onlt two variables (ID, Dob) and can do update still&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;We used to use &lt;A href="https://documentation.sas.com/doc/en/vdmmlcdc/8.1/lestmtsref/p1jjrvmzmybdeqn1gt8gj1r0ed0u.htm#p1qwrkjszinxtyn1lk4z7owpufqt" target="_self"&gt;NAMED INPUT mode&lt;/A&gt; to create the transaction datasets.&amp;nbsp; It is a little more typing per record, but it is clearer when looking at the data lines which variables each transaction is impacting.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use the IF 0 THEN SET trick to get the variables defined based on the definition in the OLD dataset.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data trans;
  if 0 then set old;
  input id gender= addm= phone= dob= ;
cards;
01 dob=2001-01-05
02 gender=M
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also note that the KEY variables need to uniquely identify the observations in the OLD dataset.&amp;nbsp; But you can have multiple transaction observations per KEY value.&amp;nbsp; They will all be applied in order so that the end result is that the NEW dataset also has the property that the KEY variables uniquely identify the observations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Sep 2023 15:24:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Alternative-to-multiple-if-statement/m-p/892577#M352535</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-09-04T15:24:25Z</dc:date>
    </item>
  </channel>
</rss>

