<?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: how to set up one variable for one of multiple data sets ? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-set-up-one-variable-for-one-of-multiple-data-sets/m-p/742302#M232161</link>
    <description>&lt;P&gt;Thank you for your help.&lt;/P&gt;</description>
    <pubDate>Tue, 18 May 2021 23:39:37 GMT</pubDate>
    <dc:creator>tianerhu</dc:creator>
    <dc:date>2021-05-18T23:39:37Z</dc:date>
    <item>
      <title>how to set up one variable for one of multiple data sets ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-set-up-one-variable-for-one-of-multiple-data-sets/m-p/742266#M232144</link>
      <description>&lt;P&gt;when I just have one SAS data set , I know how to set up a new MM variable, like below:&lt;/P&gt;
&lt;P&gt;data A;&lt;/P&gt;
&lt;P&gt;set C;&lt;/P&gt;
&lt;P&gt;input score1 score2;&lt;/P&gt;
&lt;P&gt;MM=score1+score2;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;if have two data sets ,dataA and dataB, I just want to set up a new MM variable for data set A, What should I do?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 May 2021 19:20:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-set-up-one-variable-for-one-of-multiple-data-sets/m-p/742266#M232144</guid>
      <dc:creator>tianerhu</dc:creator>
      <dc:date>2021-05-18T19:20:38Z</dc:date>
    </item>
    <item>
      <title>Re: how to set up one variable for one of multiple data sets ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-set-up-one-variable-for-one-of-multiple-data-sets/m-p/742267#M232145</link>
      <description>&lt;P&gt;You quite obviously do NOT know how to calculate the variable from one dataset:&lt;/P&gt;
&lt;PRE&gt; 79         data A;
 80         set C;
 81         input score1 score2;
 82         MM=score1+score2;
 83         run;
 
 ERROR: No DATALINES or INFILE statement.
 NOTE: The SAS System stopped processing this step because of errors.
&lt;/PRE&gt;
&lt;P&gt;or be more diligent when posting your code here. By posting garbage, you make it very hard for us to know what you want to do.&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/268447"&gt;@tianerhu&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;when I just have one SAS data set , I know how to set up a new MM variable, like below:&lt;/P&gt;
&lt;P&gt;data A;&lt;/P&gt;
&lt;P&gt;set C;&lt;/P&gt;
&lt;P&gt;input score1 score2;&lt;/P&gt;
&lt;P&gt;MM=score1+score2;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;if have two data sets ,dataA and dataB, I just want to set up a new MM variable for data set A, What should I do?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 May 2021 19:25:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-set-up-one-variable-for-one-of-multiple-data-sets/m-p/742267#M232145</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-05-18T19:25:47Z</dc:date>
    </item>
    <item>
      <title>Re: how to set up one variable for one of multiple data sets ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-set-up-one-variable-for-one-of-multiple-data-sets/m-p/742268#M232146</link>
      <description>&lt;P&gt;Remove the&amp;nbsp; INPUT statement. That is for reading text from a file.&amp;nbsp; You appear to already have a SAS dataset with the variables SCORE1 and SCORE2 on it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
  set c;
  mm= score1 + score2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that variables do not live independent of datasets.&amp;nbsp; So to add a new variable the A you need to either recreate A or create a new dataset that has the data from A and calculates the new variable(s).&amp;nbsp; So the example above creates a new dataset named A by using the data already in C.&amp;nbsp; While it is copying the data it also creates MM.&lt;/P&gt;
&lt;P&gt;If you are just a beginner do not try to overwrite your dataset by using the same name as the input and the output dataset.&amp;nbsp; That will remove the original version of the dataset and make it hard to fix and coding mistakes.&lt;/P&gt;</description>
      <pubDate>Tue, 18 May 2021 19:27:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-set-up-one-variable-for-one-of-multiple-data-sets/m-p/742268#M232146</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-05-18T19:27:40Z</dc:date>
    </item>
    <item>
      <title>Re: how to set up one variable for one of multiple data sets ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-set-up-one-variable-for-one-of-multiple-data-sets/m-p/742291#M232156</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/268447"&gt;@tianerhu&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if have two data sets ,dataA and dataB, I just want to set up a new MM variable for data set A, What should I do?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Why do you think the second data set comes in to play at all? Why can't you just ignore it?&lt;/P&gt;
&lt;P&gt;Data sets are independent unless you need information from both. But if that's the case you need to generally create a new output data set.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;It's better to not think of it as adding to a data set but as creating a new data set with a new variable added on. DBs will&amp;nbsp;overwrite a data set, but in SAS it recreates it entirely, it's not a modification/update. This means it drops the original table, creates a new one and the old one is deleted.&amp;nbsp;This happens in the background but it happens. This is different from R/Python logic.&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if your process is as follows:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Create a new variable MM as the sum of var1, var2 from data set A&lt;/LI&gt;
&lt;LI&gt;Add a new variable CC from data set B via a merge on ID&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;You should end up with&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data set A - original&lt;/P&gt;
&lt;P&gt;Data set B - original&lt;/P&gt;
&lt;P&gt;Data set A2 - from Step 1&lt;/P&gt;
&lt;P&gt;Data set A3 - from Step 3.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A2 can be dropped later if needed. If you can't understand the data flow process you can try drawing it out on paper and it will help and save you a lot of time.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 May 2021 22:19:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-set-up-one-variable-for-one-of-multiple-data-sets/m-p/742291#M232156</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-05-18T22:19:57Z</dc:date>
    </item>
    <item>
      <title>Re: how to set up one variable for one of multiple data sets ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-set-up-one-variable-for-one-of-multiple-data-sets/m-p/742301#M232160</link>
      <description>&lt;P&gt;There is something wrong with the code which I posted. Sorry about that.&lt;/P&gt;
&lt;P&gt;Thank you for your reply.&lt;/P&gt;</description>
      <pubDate>Tue, 18 May 2021 23:37:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-set-up-one-variable-for-one-of-multiple-data-sets/m-p/742301#M232160</guid>
      <dc:creator>tianerhu</dc:creator>
      <dc:date>2021-05-18T23:37:10Z</dc:date>
    </item>
    <item>
      <title>Re: how to set up one variable for one of multiple data sets ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-set-up-one-variable-for-one-of-multiple-data-sets/m-p/742302#M232161</link>
      <description>&lt;P&gt;Thank you for your help.&lt;/P&gt;</description>
      <pubDate>Tue, 18 May 2021 23:39:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-set-up-one-variable-for-one-of-multiple-data-sets/m-p/742302#M232161</guid>
      <dc:creator>tianerhu</dc:creator>
      <dc:date>2021-05-18T23:39:37Z</dc:date>
    </item>
  </channel>
</rss>

