<?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 Update colums  from one data set to another data set in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Update-colums-from-one-data-set-to-another-data-set/m-p/226153#M40673</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have forty "Question" columns in my data set. Sample of data set is below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/186iB31766192554F14A/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="data.png" title="data.png" /&gt;................................&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i have different data set too.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/187iE551911001644386/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="data2.png" title="data2.png" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My purpose is update the Current column values same as the Intended column values. After i wrote the code below. I could made it. But just for one column(Question1) How about other columns. Is it possible to change them all ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
update work.ChangeValue set Question1=(select Intended from work.work.ChangeValue2 
where Variable="Question1")
where Question1=(select Current from work.work.ChangeValue2 
where Variable="Question1");
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/188iC49A8AAED10E1017/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="data3.png" title="data3.png" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
    <pubDate>Thu, 17 Sep 2015 22:27:09 GMT</pubDate>
    <dc:creator>turcay</dc:creator>
    <dc:date>2015-09-17T22:27:09Z</dc:date>
    <item>
      <title>Update colums  from one data set to another data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-colums-from-one-data-set-to-another-data-set/m-p/226153#M40673</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have forty "Question" columns in my data set. Sample of data set is below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/186iB31766192554F14A/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="data.png" title="data.png" /&gt;................................&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i have different data set too.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/187iE551911001644386/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="data2.png" title="data2.png" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My purpose is update the Current column values same as the Intended column values. After i wrote the code below. I could made it. But just for one column(Question1) How about other columns. Is it possible to change them all ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
update work.ChangeValue set Question1=(select Intended from work.work.ChangeValue2 
where Variable="Question1")
where Question1=(select Current from work.work.ChangeValue2 
where Variable="Question1");
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/188iC49A8AAED10E1017/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="data3.png" title="data3.png" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Sep 2015 22:27:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-colums-from-one-data-set-to-another-data-set/m-p/226153#M40673</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2015-09-17T22:27:09Z</dc:date>
    </item>
    <item>
      <title>Re: Update colums  from one data set to another data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-colums-from-one-data-set-to-another-data-set/m-p/226163#M40679</link>
      <description>&lt;P&gt;Can you attempt to explain what you want in another way? &amp;nbsp;Preferable with actual before and after data.&lt;/P&gt;&lt;P&gt;It looks like you just want to force the values of the Q variables to be the same for all observations.&lt;/P&gt;&lt;P&gt;Also your first dataset does not appear to have any id variable to uniquely identify the rows. What is the meaning of the VALUE variable? &amp;nbsp;Is it important?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2015 00:44:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-colums-from-one-data-set-to-another-data-set/m-p/226163#M40679</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2015-09-18T00:44:21Z</dc:date>
    </item>
    <item>
      <title>Re: Update colums  from one data set to another data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-colums-from-one-data-set-to-another-data-set/m-p/226167#M40682</link>
      <description>&lt;P&gt;It sounds like you want the equivalent of this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if question1=2 then question1=1;&lt;/P&gt;&lt;P&gt;if question3=4 then question3=3;&lt;/P&gt;&lt;P&gt;if question5=1 then question5=2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But you want the actual set of changes to be based on your second data set.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does that sound about right?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Are you locked in to using SQL UPDATE, or would any working approach be OK?&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2015 01:30:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-colums-from-one-data-set-to-another-data-set/m-p/226167#M40682</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-09-18T01:30:24Z</dc:date>
    </item>
    <item>
      <title>Re: Update colums  from one data set to another data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-colums-from-one-data-set-to-another-data-set/m-p/226173#M40684</link>
      <description>&lt;P&gt;Generate the SQL update statements dynamically (lazy typist version):&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input v q1 q2 q3;
datalines;
10 1 2 3
20 2 3 4 
30 3 4 1
40 2 3 4
;

data change;
input v $ i c;
datalines;
q1 4 2
q3 2 1
;

proc print data=test; run;

data _null_;
set change;
if _n_ = 1 then call execute('Proc sql;');
call execute(catx(" ", 'update test set', v, '=', i, 'where', v, '=', c, ';'));
run;

proc print data=test; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Sep 2015 02:28:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-colums-from-one-data-set-to-another-data-set/m-p/226173#M40684</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2015-09-18T02:28:35Z</dc:date>
    </item>
    <item>
      <title>Re: Update colums  from one data set to another data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-colums-from-one-data-set-to-another-data-set/m-p/226193#M40688</link>
      <description>Under Astounding Help. Maybe I understand what you mean.You'd better post some SAS data code , NOT photo, No one will type these data for you . Try this one : (using PG's data)&lt;PRE&gt;data test;
input value q1 q2 q3;
datalines;
10 1 2 3
20 2 3 4 
30 3 4 1
40 2 3 4
;
run;
data change;
input variable $ i c;
datalines;
q1 4 2
q3 2 1
;
run;
data want;
 if _n_ eq 1 then do;
  if 0 then set change;
  declare hash ha(dataset:'change');
  ha.definekey('variable','c');
  ha.definedata('i');
  ha.definedone();
 end;
set test;
array x{*} q1-q3;
do k=1 to dim(x);
 variable=vname(x{k});
 c=x{k};
 if ha.find()=0 then x{k}=i;
end;
drop k variable i c;
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Sep 2015 05:34:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-colums-from-one-data-set-to-another-data-set/m-p/226193#M40688</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2015-09-18T05:34:39Z</dc:date>
    </item>
    <item>
      <title>Re: Update colums  from one data set to another data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-colums-from-one-data-set-to-another-data-set/m-p/226342#M40732</link>
      <description>&lt;P&gt;I am making a big guess here but this looks like it may be a recoding where the data values represent question answer codes and the codes used to represent the same value (Yes/No or Always/sometimes/never or such) changed between data collection periods.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;IF that is the case then I would suggest using custom informats for each question response group.&lt;/P&gt;&lt;P&gt;For example if I had a variable that in a previous collection cycle was coded as:&lt;/P&gt;&lt;P&gt;1 = Often&lt;/P&gt;&lt;P&gt;2 = Sometimes&lt;/P&gt;&lt;P&gt;3 =&amp;nbsp;Seldom&lt;/P&gt;&lt;P&gt;and we changed the coding to reflect something like:&lt;/P&gt;&lt;P&gt;1 = Always&lt;/P&gt;&lt;P&gt;2 = Usually&lt;/P&gt;&lt;P&gt;3 = Sometimes&lt;/P&gt;&lt;P&gt;4 = Not often&lt;/P&gt;&lt;P&gt;5 = Never&lt;/P&gt;&lt;P&gt;I might want to match the previous response of 1 (often) to the current coding of 2 (usually). I'm not saying this is a good idea, just to set the stage.&lt;/P&gt;&lt;P&gt;So to re-code the old data to the new standard:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
invalue recode
1 = 2
3 = 4
other= _same_; /* assumes some values map to the same numeric*/
run;

/*Use as :*/
Data want;
   set have ;
   Question1 = input(question1,recode.);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This approach works very well if you have multiple questions / data values with the same scale.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note, this will generate a message about numeric to character conversions.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2015 15:53:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-colums-from-one-data-set-to-another-data-set/m-p/226342#M40732</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-09-18T15:53:28Z</dc:date>
    </item>
    <item>
      <title>Re: Update colums  from one data set to another data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Update-colums-from-one-data-set-to-another-data-set/m-p/226385#M40742</link>
      <description>&lt;P&gt;Thanks everyone. I posted photos because i think it is the best way to tell what i try to do and i also post my SAS code to describe you. Everyone helps me within this this period i imporove my skills. I try to find best way to use memory more efficiency. I guess less data steps or proc sql steps more efficiency. Thanks again.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2015 19:58:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Update-colums-from-one-data-set-to-another-data-set/m-p/226385#M40742</guid>
      <dc:creator>turcay</dc:creator>
      <dc:date>2015-09-18T19:58:59Z</dc:date>
    </item>
  </channel>
</rss>

