<?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: insertion of corrected variable values in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/insertion-of-corrected-variable-values/m-p/73329#M21253</link>
    <description>Hi Marie&lt;BR /&gt;
Not a macro but it should work.&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick&lt;BR /&gt;
&lt;BR /&gt;
data NewVals;&lt;BR /&gt;
  infile datalines dsd dlm=';' truncover;&lt;BR /&gt;
  input No Id VariableName $ newValue;&lt;BR /&gt;
  drop No;&lt;BR /&gt;
datalines4;&lt;BR /&gt;
1;501;Var1;100&lt;BR /&gt;
2;512;Var2;101&lt;BR /&gt;
3;523;Var3;102&lt;BR /&gt;
4;534;Var4;103&lt;BR /&gt;
5;545;Var4;104&lt;BR /&gt;
6;556;Var4;105&lt;BR /&gt;
7;567;Var5;106&lt;BR /&gt;
8;578;Var6;107&lt;BR /&gt;
9;589;Var7;108&lt;BR /&gt;
10;600;Var7;109&lt;BR /&gt;
;;;;&lt;BR /&gt;
&lt;BR /&gt;
data InitialVals;&lt;BR /&gt;
  infile datalines dsd dlm=';' truncover;&lt;BR /&gt;
  input ID Var1 Var2 Var3 Var4 Var5 Var6 Var7;&lt;BR /&gt;
datalines4;&lt;BR /&gt;
501;10;20;33;;13;;;&lt;BR /&gt;
512;11;;32;;75;;;&lt;BR /&gt;
523;12;21;56;;69;;;&lt;BR /&gt;
534;13;22;34;46;35;;;&lt;BR /&gt;
545;14;23;34;;;56;;&lt;BR /&gt;
556;15;;36;;73;;54&lt;BR /&gt;
567;16;24;37;;;;;&lt;BR /&gt;
578;17;25;;;;;;&lt;BR /&gt;
589;18;26;38;;99;78;;&lt;BR /&gt;
600;;27;;;55;;54&lt;BR /&gt;
;;;;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
/* Create identical data structures */&lt;BR /&gt;
proc transpose data=NewVals out=NewValsTransposed;&lt;BR /&gt;
  id VariableName;&lt;BR /&gt;
  by id;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
/* make sure all variables exist in DS NewValsTransposed */&lt;BR /&gt;
data mapping;&lt;BR /&gt;
  stop;&lt;BR /&gt;
  set InitialVals;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data NewValsTransposedMapped /view=NewValsTransposedMapped;&lt;BR /&gt;
  set mapping NewValsTransposed;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
/* Amend values */&lt;BR /&gt;
proc sql;&lt;BR /&gt;
  create table CorrectedVals as&lt;BR /&gt;
    select &lt;BR /&gt;
      I.ID,&lt;BR /&gt;
      coalesce(T.Var1,I.Var1) as Var1,&lt;BR /&gt;
      coalesce(T.Var2,I.Var2) as Var2,&lt;BR /&gt;
      coalesce(T.Var3,I.Var3) as Var3,&lt;BR /&gt;
      coalesce(T.Var4,I.Var4) as Var4,&lt;BR /&gt;
      coalesce(T.Var5,I.Var5) as Var5,&lt;BR /&gt;
      coalesce(T.Var6,I.Var6) as Var6,&lt;BR /&gt;
      coalesce(T.Var7,I.Var7) as Var7&lt;BR /&gt;
      from InitialVals as I left join NewValsTransposedMapped as T&lt;BR /&gt;
        on I.ID=T.ID;&lt;BR /&gt;
quit;</description>
    <pubDate>Fri, 25 Sep 2009 09:45:42 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2009-09-25T09:45:42Z</dc:date>
    <item>
      <title>insertion of corrected variable values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/insertion-of-corrected-variable-values/m-p/73328#M21252</link>
      <description>hi guys,&lt;BR /&gt;
&lt;BR /&gt;
i have a problem:i have a table Beispiel1: &lt;BR /&gt;
&lt;BR /&gt;
No....Id......VariableName...newValue&lt;BR /&gt;
1......501...Var1.................100&lt;BR /&gt;
2......512...Var2.................101&lt;BR /&gt;
3......523...Var3.................102&lt;BR /&gt;
4......534...Var4.................103&lt;BR /&gt;
5......545...Var4.................104&lt;BR /&gt;
6......556...Var4.................105&lt;BR /&gt;
7......567...Var5.................106&lt;BR /&gt;
8......578...Var6.................107&lt;BR /&gt;
9......589...Var7.................108&lt;BR /&gt;
10....600...Var7.................109&lt;BR /&gt;
&lt;BR /&gt;
where i have corrected values for another table Beispiel2:&lt;BR /&gt;
&lt;BR /&gt;
ID.....Var1..Var2..Var3..Var4..Var5..Var...Var7&lt;BR /&gt;
501...10.....20......33......__	....13......__...__			&lt;BR /&gt;
512...11.....__......32......__	....75......__...__			&lt;BR /&gt;
523...12.....21......56......__	....69......__...__			&lt;BR /&gt;
534...13.....22......34......46	....35......__...__		&lt;BR /&gt;
545...14.....23......34......__	....__......56...__	&lt;BR /&gt;
556...15.....__......36......__....73......__...54&lt;BR /&gt;
567...16.....24......37......__....__......__...__				&lt;BR /&gt;
578...17.....25......__......__....__......__...__				&lt;BR /&gt;
589...18.....26......38......__....99	......78...__				&lt;BR /&gt;
600...__.....27......__......__	....55......__...54					&lt;BR /&gt;
&lt;BR /&gt;
know i would like to program a macro which automatically set the new value into the variable in Beispiel2 which is written in the variable 'variableName' in Beispiel1.&lt;BR /&gt;
&lt;BR /&gt;
Do you have any idea how i can programm this or how i can call a column when the name variables with every row?&lt;BR /&gt;
i thought about something like this but i think its not possible that way.?!:&lt;BR /&gt;
&lt;BR /&gt;
Data central;&lt;BR /&gt;
merge Beispiel1(in=a) Beispiel2 (in=b);&lt;BR /&gt;
by ID;&lt;BR /&gt;
Run;&lt;BR /&gt;
&lt;BR /&gt;
Data test;&lt;BR /&gt;
Set central;&lt;BR /&gt;
array arr{*} $ n1-n10;&lt;BR /&gt;
DO i=1 to 10;&lt;BR /&gt;
If No= i Then arr{i}= VariablenName;&lt;BR /&gt;
Set (here i need the content of:) arr{i}=NewValue&lt;BR /&gt;
Where No=i;&lt;BR /&gt;
End;&lt;BR /&gt;
&lt;BR /&gt;
Run;&lt;BR /&gt;
&lt;BR /&gt;
thank you very much for your suggestions!&lt;BR /&gt;
&lt;BR /&gt;
Marie

Message was edited by: marieK</description>
      <pubDate>Fri, 25 Sep 2009 08:49:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/insertion-of-corrected-variable-values/m-p/73328#M21252</guid>
      <dc:creator>marieK</dc:creator>
      <dc:date>2009-09-25T08:49:19Z</dc:date>
    </item>
    <item>
      <title>Re: insertion of corrected variable values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/insertion-of-corrected-variable-values/m-p/73329#M21253</link>
      <description>Hi Marie&lt;BR /&gt;
Not a macro but it should work.&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick&lt;BR /&gt;
&lt;BR /&gt;
data NewVals;&lt;BR /&gt;
  infile datalines dsd dlm=';' truncover;&lt;BR /&gt;
  input No Id VariableName $ newValue;&lt;BR /&gt;
  drop No;&lt;BR /&gt;
datalines4;&lt;BR /&gt;
1;501;Var1;100&lt;BR /&gt;
2;512;Var2;101&lt;BR /&gt;
3;523;Var3;102&lt;BR /&gt;
4;534;Var4;103&lt;BR /&gt;
5;545;Var4;104&lt;BR /&gt;
6;556;Var4;105&lt;BR /&gt;
7;567;Var5;106&lt;BR /&gt;
8;578;Var6;107&lt;BR /&gt;
9;589;Var7;108&lt;BR /&gt;
10;600;Var7;109&lt;BR /&gt;
;;;;&lt;BR /&gt;
&lt;BR /&gt;
data InitialVals;&lt;BR /&gt;
  infile datalines dsd dlm=';' truncover;&lt;BR /&gt;
  input ID Var1 Var2 Var3 Var4 Var5 Var6 Var7;&lt;BR /&gt;
datalines4;&lt;BR /&gt;
501;10;20;33;;13;;;&lt;BR /&gt;
512;11;;32;;75;;;&lt;BR /&gt;
523;12;21;56;;69;;;&lt;BR /&gt;
534;13;22;34;46;35;;;&lt;BR /&gt;
545;14;23;34;;;56;;&lt;BR /&gt;
556;15;;36;;73;;54&lt;BR /&gt;
567;16;24;37;;;;;&lt;BR /&gt;
578;17;25;;;;;;&lt;BR /&gt;
589;18;26;38;;99;78;;&lt;BR /&gt;
600;;27;;;55;;54&lt;BR /&gt;
;;;;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
/* Create identical data structures */&lt;BR /&gt;
proc transpose data=NewVals out=NewValsTransposed;&lt;BR /&gt;
  id VariableName;&lt;BR /&gt;
  by id;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
/* make sure all variables exist in DS NewValsTransposed */&lt;BR /&gt;
data mapping;&lt;BR /&gt;
  stop;&lt;BR /&gt;
  set InitialVals;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data NewValsTransposedMapped /view=NewValsTransposedMapped;&lt;BR /&gt;
  set mapping NewValsTransposed;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
/* Amend values */&lt;BR /&gt;
proc sql;&lt;BR /&gt;
  create table CorrectedVals as&lt;BR /&gt;
    select &lt;BR /&gt;
      I.ID,&lt;BR /&gt;
      coalesce(T.Var1,I.Var1) as Var1,&lt;BR /&gt;
      coalesce(T.Var2,I.Var2) as Var2,&lt;BR /&gt;
      coalesce(T.Var3,I.Var3) as Var3,&lt;BR /&gt;
      coalesce(T.Var4,I.Var4) as Var4,&lt;BR /&gt;
      coalesce(T.Var5,I.Var5) as Var5,&lt;BR /&gt;
      coalesce(T.Var6,I.Var6) as Var6,&lt;BR /&gt;
      coalesce(T.Var7,I.Var7) as Var7&lt;BR /&gt;
      from InitialVals as I left join NewValsTransposedMapped as T&lt;BR /&gt;
        on I.ID=T.ID;&lt;BR /&gt;
quit;</description>
      <pubDate>Fri, 25 Sep 2009 09:45:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/insertion-of-corrected-variable-values/m-p/73329#M21253</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2009-09-25T09:45:42Z</dc:date>
    </item>
    <item>
      <title>Re: insertion of corrected variable values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/insertion-of-corrected-variable-values/m-p/73330#M21254</link>
      <description>hi Patrick,&lt;BR /&gt;
&lt;BR /&gt;
thanks for your very fast answer. if i run the programm i get an error message: &lt;BR /&gt;
&lt;BR /&gt;
'ERROR: Utility file open failed.&lt;BR /&gt;
NOTE: Table WORK.CORRECTEDVALS created, with 0 rows and 8 columns.&lt;BR /&gt;
&lt;BR /&gt;
NOTE: View WORK.NEWVALSTRANSPOSEDMAPPED.VIEW used (Total process time):&lt;BR /&gt;
      real time           1.01 seconds&lt;BR /&gt;
      cpu time            0.07 second&lt;BR /&gt;
'&lt;BR /&gt;
my problem is, that i have a program with 200 variables. i am looking for a code where i don´t have to write that:&lt;BR /&gt;
&lt;BR /&gt;
oalesce(T.Var1,I.Var1) as Var1,&lt;BR /&gt;
coalesce(T.Var2,I.Var2) as Var2,&lt;BR /&gt;
coalesce(T.Var3,I.Var3) as Var3,&lt;BR /&gt;
coalesce(T.Var4,I.Var4) as Var4,&lt;BR /&gt;
coalesce(T.Var5,I.Var5) as Var5,&lt;BR /&gt;
coalesce(T.Var6,I.Var6) as Var6,&lt;BR /&gt;
coalesce(T.Var7,I.Var7) as Var7&lt;BR /&gt;
&lt;BR /&gt;
for 200 variables.... is there any other possibility??</description>
      <pubDate>Fri, 25 Sep 2009 10:01:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/insertion-of-corrected-variable-values/m-p/73330#M21254</guid>
      <dc:creator>marieK</dc:creator>
      <dc:date>2009-09-25T10:01:20Z</dc:date>
    </item>
    <item>
      <title>Re: insertion of corrected variable values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/insertion-of-corrected-variable-values/m-p/73331#M21255</link>
      <description>Hi Marie&lt;BR /&gt;
The code runs without error on my machine (sas9.1.3 under windows).&lt;BR /&gt;
Your 200 vars: Working on something more versatile - it will mainly be querying the dictionary to retrieve the list of variables.&lt;BR /&gt;
Regards, Patrick</description>
      <pubDate>Fri, 25 Sep 2009 10:44:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/insertion-of-corrected-variable-values/m-p/73331#M21255</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2009-09-25T10:44:58Z</dc:date>
    </item>
    <item>
      <title>Re: insertion of corrected variable values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/insertion-of-corrected-variable-values/m-p/73332#M21256</link>
      <description>Hi Marie&lt;BR /&gt;
That should give you an idea how to do it.&lt;BR /&gt;
The error you mentioned must be based on something else in your code.&lt;BR /&gt;
If you have an EG session then best re-connect to the server before you run the code to make sure that you test in a "clean" session.&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick&lt;BR /&gt;
&lt;BR /&gt;
data NewVals;&lt;BR /&gt;
  infile datalines dsd dlm=';' truncover;&lt;BR /&gt;
  input No Id VariableName $ newValue;&lt;BR /&gt;
  drop No;&lt;BR /&gt;
datalines4;&lt;BR /&gt;
1;501;Var1;100&lt;BR /&gt;
2;512;Var2;101&lt;BR /&gt;
3;523;Var3;102&lt;BR /&gt;
4;534;Var4;103&lt;BR /&gt;
5;545;Var4;104&lt;BR /&gt;
6;556;Var4;105&lt;BR /&gt;
7;567;Var5;106&lt;BR /&gt;
8;578;Var6;107&lt;BR /&gt;
9;589;Var7;108&lt;BR /&gt;
10;600;Var7;109&lt;BR /&gt;
;;;;&lt;BR /&gt;
&lt;BR /&gt;
data InitialVals;&lt;BR /&gt;
  infile datalines dsd dlm=';' truncover;&lt;BR /&gt;
  input ID Var1 Var2 Var3 Var4 Var5 Var6 Var7;&lt;BR /&gt;
datalines4;&lt;BR /&gt;
501;10;20;33;;13;;;&lt;BR /&gt;
512;11;;32;;75;;;&lt;BR /&gt;
523;12;21;56;;69;;;&lt;BR /&gt;
534;13;22;34;46;35;;;&lt;BR /&gt;
545;14;23;34;;;56;;&lt;BR /&gt;
556;15;;36;;73;;54&lt;BR /&gt;
567;16;24;37;;;;;&lt;BR /&gt;
578;17;25;;;;;;&lt;BR /&gt;
589;18;26;38;;99;78;;&lt;BR /&gt;
600;;27;;;55;;54&lt;BR /&gt;
;;;;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
/* Create identical data structures */&lt;BR /&gt;
proc transpose data=NewVals out=NewValsTransposed;&lt;BR /&gt;
  id VariableName;&lt;BR /&gt;
  by id;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
/* make sure all variables exist in DS NewValsTransposed */&lt;BR /&gt;
data mapping;&lt;BR /&gt;
  stop;&lt;BR /&gt;
  set InitialVals;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data NewValsTransposedMapped /view=NewValsTransposedMapped;&lt;BR /&gt;
  set mapping NewValsTransposed;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
/* Amend values */&lt;BR /&gt;
proc sql noprint;&lt;BR /&gt;
  /* build coalesce statements */&lt;BR /&gt;
  select cats('coalesce (T.',name,',I.',name)||') as '||strip(name) into :SelectList separated by ','&lt;BR /&gt;
    from dictionary.columns&lt;BR /&gt;
      where libname ='WORK' and memname='INITIALVALS' and memtype='DATA' and name ne 'ID';&lt;BR /&gt;
&lt;BR /&gt;
  /* amend values in table */&lt;BR /&gt;
  create table CorrectedVals as&lt;BR /&gt;
    select &lt;BR /&gt;
        I.ID,&lt;BR /&gt;
        &amp;amp;SelectList&lt;BR /&gt;
      from InitialVals as I left join NewValsTransposedMapped as T&lt;BR /&gt;
        on I.ID=T.ID;&lt;BR /&gt;
&lt;BR /&gt;
  /* clean up */&lt;BR /&gt;
  drop table mapping;&lt;BR /&gt;
  drop table NewVals;&lt;BR /&gt;
  drop table NewValsTransposed;&lt;BR /&gt;
  drop view NewValsTransposedMapped;&lt;BR /&gt;
quit;</description>
      <pubDate>Fri, 25 Sep 2009 11:10:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/insertion-of-corrected-variable-values/m-p/73332#M21256</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2009-09-25T11:10:55Z</dc:date>
    </item>
    <item>
      <title>Re: insertion of corrected variable values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/insertion-of-corrected-variable-values/m-p/73333#M21257</link>
      <description>And here another approach. I like it less as it is transposing the "big" dataset twice.&lt;BR /&gt;
&lt;BR /&gt;
P.S: This and my earlier code examples assume that the DS with the new values does not contain missings, meaning that the correction is never setting an existing value to missing.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data NewVals;&lt;BR /&gt;
  infile datalines dsd dlm=';' truncover;&lt;BR /&gt;
  input No Id VariableName $ newValue;&lt;BR /&gt;
  drop No;&lt;BR /&gt;
datalines4;&lt;BR /&gt;
1;501;Var1;100&lt;BR /&gt;
2;512;Var2;101&lt;BR /&gt;
3;523;Var3;102&lt;BR /&gt;
4;534;Var4;103&lt;BR /&gt;
5;545;Var4;104&lt;BR /&gt;
6;556;Var4;105&lt;BR /&gt;
7;567;Var5;106&lt;BR /&gt;
8;578;Var6;107&lt;BR /&gt;
9;589;Var7;108&lt;BR /&gt;
10;600;Var7;109&lt;BR /&gt;
;;;;&lt;BR /&gt;
&lt;BR /&gt;
data InitialVals;&lt;BR /&gt;
  infile datalines dsd dlm=';' truncover;&lt;BR /&gt;
  input ID Var1 Var2 Var3 Var4 Var5 Var6 Var7;&lt;BR /&gt;
datalines4;&lt;BR /&gt;
501;10;20;33;;13;;;&lt;BR /&gt;
512;11;;32;;75;;;&lt;BR /&gt;
523;12;21;56;;69;;;&lt;BR /&gt;
534;13;22;34;46;35;;;&lt;BR /&gt;
545;14;23;34;;;56;;&lt;BR /&gt;
556;15;;36;;73;;54&lt;BR /&gt;
567;16;24;37;;;;;&lt;BR /&gt;
578;17;25;;;;;;&lt;BR /&gt;
589;18;26;38;;99;78;;&lt;BR /&gt;
600;;27;;;55;;54&lt;BR /&gt;
;;;;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
/* Create identical data structures */&lt;BR /&gt;
proc transpose data=InitialVals out=InitialValsTransposed(rename=(_name_=VariableName col1=newValue));&lt;BR /&gt;
  by id;&lt;BR /&gt;
  var Var:;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
/* join the 2 DS */&lt;BR /&gt;
proc sql;&lt;BR /&gt;
  create table InitialValsTransposedAmended as&lt;BR /&gt;
  select I.Id,I.VariableName, coalesce(N.newValue,I.newValue)&lt;BR /&gt;
    from InitialValsTransposed as I left join NewVals as N&lt;BR /&gt;
      on I.id=N.id and upcase(strip(I.VariableName))=upcase(strip(N.VariableName));&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
/* restore original data structure */&lt;BR /&gt;
proc transpose data=InitialValsTransposedAmended out=InitialValsAmended(drop=_name_);&lt;BR /&gt;
  id VariableName;&lt;BR /&gt;
  by id;&lt;BR /&gt;
run;

added upcase(strip(...)) to avoid issues with case and blanks&lt;BR /&gt;
    &lt;BR /&gt;
Message was edited by: Patrick</description>
      <pubDate>Fri, 25 Sep 2009 11:48:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/insertion-of-corrected-variable-values/m-p/73333#M21257</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2009-09-25T11:48:44Z</dc:date>
    </item>
    <item>
      <title>Re: insertion of corrected variable values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/insertion-of-corrected-variable-values/m-p/73334#M21258</link>
      <description>greaaat it works &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt; thank you so much!! (i took the last version)

Message was edited by: marieK</description>
      <pubDate>Fri, 25 Sep 2009 12:34:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/insertion-of-corrected-variable-values/m-p/73334#M21258</guid>
      <dc:creator>marieK</dc:creator>
      <dc:date>2009-09-25T12:34:22Z</dc:date>
    </item>
    <item>
      <title>Re: insertion of corrected variable values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/insertion-of-corrected-variable-values/m-p/73335#M21259</link>
      <description>hi its me again &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;BR /&gt;
&lt;BR /&gt;
everything worked with my example-datasets.... &lt;BR /&gt;
now i have a problem with the real one..&lt;BR /&gt;
&lt;BR /&gt;
my macro:&lt;BR /&gt;
&lt;BR /&gt;
* &lt;BR /&gt;
Initial: the dataset that should be corrected,&lt;BR /&gt;
idVar: the ID Variable (depends on the initial-dataset)&lt;BR /&gt;
NewVals: the table with the corrected values&lt;BR /&gt;
Final: Output-Dataset;&lt;BR /&gt;
&lt;BR /&gt;
%Macro correct (Initial=, idVar=, NewVals=, Final=);&lt;BR /&gt;
&lt;BR /&gt;
/* filter (in the NewVals Table are two IDs for different original tables. thats why i have to filter. to get just datalines for the original table where i want to correct the values. ) */&lt;BR /&gt;
&lt;BR /&gt;
proc SQL;&lt;BR /&gt;
Create Table correkt_&amp;amp;idVar as&lt;BR /&gt;
Select * From &amp;amp;NewVals&lt;BR /&gt;
Where &amp;amp;idVar IS NOT NULL;&lt;BR /&gt;
Quit;&lt;BR /&gt;
&lt;BR /&gt;
/* sort */&lt;BR /&gt;
Proc Sort data=correkt_&amp;amp;idVar;&lt;BR /&gt;
by &amp;amp;idVar;&lt;BR /&gt;
Run;&lt;BR /&gt;
&lt;BR /&gt;
proc Sort data=&amp;amp;Initial;&lt;BR /&gt;
by &amp;amp;idVar;&lt;BR /&gt;
Run;&lt;BR /&gt;
&lt;BR /&gt;
/* Create identical data structures */&lt;BR /&gt;
proc transpose data=&amp;amp;Initial out=&amp;amp;Initial.Transposed(rename=(_name_=VariableName col1=NewValue));&lt;BR /&gt;
by &amp;amp;idVar;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
/* join the 2 DS */&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table &amp;amp;Initial.TransposedAmended as&lt;BR /&gt;
select I.&amp;amp;idVar,I.VariableName, coalesce(N.NewValue,I.NewValue)&lt;BR /&gt;
from &amp;amp;Initial.Transposed as I left join &amp;amp;NewVals as N&lt;BR /&gt;
on I.&amp;amp;idVar=N.&amp;amp;idVar and upcase(strip(I.VariableName))=upcase(strip(N.VariableName));&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
/* restore original data structure */&lt;BR /&gt;
proc transpose data=&amp;amp;Initial.TransposedAmended out=&amp;amp;Final(drop=_name_);&lt;BR /&gt;
id VariableName;&lt;BR /&gt;
by &amp;amp;idVar;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
%Mend correct;&lt;BR /&gt;
&lt;BR /&gt;
i get following error message:&lt;BR /&gt;
&lt;BR /&gt;
ERROR: The COALESCE function requires its arguments to be of the same data type.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
because i have numeric and character values in my original dataset and in the newVals-dataset is everything character...

Message was edited by: marieK</description>
      <pubDate>Wed, 30 Sep 2009 09:28:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/insertion-of-corrected-variable-values/m-p/73335#M21259</guid>
      <dc:creator>marieK</dc:creator>
      <dc:date>2009-09-30T09:28:59Z</dc:date>
    </item>
    <item>
      <title>Re: insertion of corrected variable values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/insertion-of-corrected-variable-values/m-p/73336#M21260</link>
      <description>also the proc transpose doesnt work with different data-types...&lt;BR /&gt;
&lt;BR /&gt;
any idea?</description>
      <pubDate>Wed, 30 Sep 2009 12:06:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/insertion-of-corrected-variable-values/m-p/73336#M21260</guid>
      <dc:creator>marieK</dc:creator>
      <dc:date>2009-09-30T12:06:01Z</dc:date>
    </item>
    <item>
      <title>Re: insertion of corrected variable values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/insertion-of-corrected-variable-values/m-p/73337#M21261</link>
      <description>&amp;gt; because i have numeric and character values in my&lt;BR /&gt;
&amp;gt; original dataset and in the newVals-dataset is&lt;BR /&gt;
&amp;gt; everything character...&lt;BR /&gt;
&lt;BR /&gt;
You will need to use the variable type info in "INITIALVALS" to "fix up" the data in "NEWVALS" with a character and numeric version of variable "VALUE".&lt;BR /&gt;
&lt;BR /&gt;
Then I would use the good old UPDATE statement to apply the transactions.&lt;BR /&gt;
&lt;BR /&gt;
for example.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data InitialVals;&lt;BR /&gt;
   infile datalines dsd dlm=';' truncover;&lt;BR /&gt;
   input ID Var1 Var2:$8. Var3 Var4:$8. Var5 Var6 Var7;&lt;BR /&gt;
   datalines4;&lt;BR /&gt;
501;10;20;33;;13;;;&lt;BR /&gt;
512;11;;32;;75;;;&lt;BR /&gt;
523;12;21;56;;69;;;&lt;BR /&gt;
534;13;22;34;46;35;;;&lt;BR /&gt;
545;14;23;34;;;56;;&lt;BR /&gt;
556;15;;36;;73;;54&lt;BR /&gt;
567;16;24;37;;;;;&lt;BR /&gt;
578;17;25;;;;;;&lt;BR /&gt;
589;18;26;38;;99;78;;&lt;BR /&gt;
600;;27;;;55;;54&lt;BR /&gt;
;;;;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc contents order=varnum;&lt;BR /&gt;
   run;&lt;BR /&gt;
&lt;BR /&gt;
data NewVals(keep=id VariableName cValue nValue);&lt;BR /&gt;
   infile datalines dsd dlm=';' truncover;&lt;BR /&gt;
   input No Id VariableName $ Value:$8.;&lt;BR /&gt;
   select(vtypeX(variableName));&lt;BR /&gt;
      when('C') cValue = value;&lt;BR /&gt;
      when('N') nValue = input(value,f12.);&lt;BR /&gt;
      otherwise;&lt;BR /&gt;
      end;&lt;BR /&gt;
   return;&lt;BR /&gt;
   set initialVals(keep=var:);&lt;BR /&gt;
   datalines4;&lt;BR /&gt;
1;501;Var1;100&lt;BR /&gt;
2;512;Var2;101&lt;BR /&gt;
3;523;Var3;102&lt;BR /&gt;
4;534;Var4;103&lt;BR /&gt;
5;545;Var4;104&lt;BR /&gt;
6;556;Var4;105&lt;BR /&gt;
7;567;Var5;106&lt;BR /&gt;
8;578;Var6;107&lt;BR /&gt;
9;589;Var7;108&lt;BR /&gt;
10;600;Var7;109&lt;BR /&gt;
;;;;&lt;BR /&gt;
   run;&lt;BR /&gt;
&lt;BR /&gt;
proc transpose data=newVals out=cvals(drop=_name_);&lt;BR /&gt;
   where not missing(cvalue);&lt;BR /&gt;
   by id;&lt;BR /&gt;
   var cvalue;&lt;BR /&gt;
   id variableName;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc transpose data=newVals out=nvals(drop=_name_);&lt;BR /&gt;
   where not missing(nvalue);&lt;BR /&gt;
   by id;&lt;BR /&gt;
   var nvalue;&lt;BR /&gt;
   id variableName;&lt;BR /&gt;
   run;&lt;BR /&gt;
data trans;&lt;BR /&gt;
   merge cvals nvals;&lt;BR /&gt;
   by id;&lt;BR /&gt;
   run;&lt;BR /&gt;
 &lt;BR /&gt;
data updated;&lt;BR /&gt;
   update initialVals trans;&lt;BR /&gt;
   by id;&lt;BR /&gt;
   run;&lt;BR /&gt;
Proc print;&lt;BR /&gt;
   run;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Wed, 30 Sep 2009 12:14:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/insertion-of-corrected-variable-values/m-p/73337#M21261</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2009-09-30T12:14:57Z</dc:date>
    </item>
    <item>
      <title>Re: insertion of corrected variable values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/insertion-of-corrected-variable-values/m-p/73338#M21262</link>
      <description>thanks!! i will try it out&lt;BR /&gt;
but how can i to this part:&lt;BR /&gt;
&lt;BR /&gt;
data NewVals(keep=id VariableName cValue nValue);&lt;BR /&gt;
   infile datalines dsd dlm=';' truncover;&lt;BR /&gt;
   input No Id VariableName $ Value:$8.;&lt;BR /&gt;
   select(vtypeX(variableName));&lt;BR /&gt;
      when('C') cValue = value;&lt;BR /&gt;
      when('N') nValue = input(value,f12.);&lt;BR /&gt;
      otherwise;&lt;BR /&gt;
      end;&lt;BR /&gt;
   return;&lt;BR /&gt;
   set initialVals(keep=var:);&lt;BR /&gt;
   datalines4;&lt;BR /&gt;
1;501;Var1;100&lt;BR /&gt;
2;512;Var2;101&lt;BR /&gt;
3;523;Var3;102&lt;BR /&gt;
4;534;Var4;103&lt;BR /&gt;
5;545;Var4;104&lt;BR /&gt;
6;556;Var4;105&lt;BR /&gt;
7;567;Var5;106&lt;BR /&gt;
8;578;Var6;107&lt;BR /&gt;
9;589;Var7;108&lt;BR /&gt;
10;600;Var7;109&lt;BR /&gt;
;;;;&lt;BR /&gt;
   run;&lt;BR /&gt;
&lt;BR /&gt;
when i have a xls-file???

Message was edited by: marieK</description>
      <pubDate>Wed, 30 Sep 2009 13:59:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/insertion-of-corrected-variable-values/m-p/73338#M21262</guid>
      <dc:creator>marieK</dc:creator>
      <dc:date>2009-09-30T13:59:30Z</dc:date>
    </item>
    <item>
      <title>Re: insertion of corrected variable values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/insertion-of-corrected-variable-values/m-p/73339#M21263</link>
      <description>The question if not clear.  &lt;BR /&gt;
&lt;BR /&gt;
You used PROC IMPORT to get " NewVals" from XLS?&lt;BR /&gt;
&lt;BR /&gt;
If so then use data step similar to&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data NewVals(keep=id VariableName cValue nValue);&lt;BR /&gt;
   set &lt;DATA from="" proc="" import=""&gt;;&lt;BR /&gt;
   select(vtypeX(variableName));&lt;BR /&gt;
      when('C') cValue = value;&lt;BR /&gt;
      when('N') nValue = input(value,f12.);&lt;BR /&gt;
      otherwise;&lt;BR /&gt;
      end;&lt;BR /&gt;
   return;&lt;BR /&gt;
   set initialVals(keep=var:);[/pre]&lt;/DATA&gt;</description>
      <pubDate>Wed, 30 Sep 2009 14:06:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/insertion-of-corrected-variable-values/m-p/73339#M21263</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2009-09-30T14:06:21Z</dc:date>
    </item>
    <item>
      <title>Re: insertion of corrected variable values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/insertion-of-corrected-variable-values/m-p/73340#M21264</link>
      <description>thank u so much! everything works!&lt;BR /&gt;
&lt;BR /&gt;
just had  to compress my value then everything was all right &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;</description>
      <pubDate>Wed, 30 Sep 2009 15:15:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/insertion-of-corrected-variable-values/m-p/73340#M21264</guid>
      <dc:creator>marieK</dc:creator>
      <dc:date>2009-09-30T15:15:16Z</dc:date>
    </item>
  </channel>
</rss>

