<?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: Replacing missing column variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Replacing-missing-column-variables/m-p/696739#M212865</link>
    <description>&lt;P&gt;Just need define temp1 and temp2 variables as char type by assigning $&amp;lt;length&amp;gt;:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data new;
set Xall_final10_2;
length temp1 temp2 $3;
retain temp1 temp2;
if param = "ka1" and col2 ne . then temp1 = param; else 
if param = "ka2" and col2 ne . then temp2 = param; else
if col2 = . then do;
  if param = "ka1" then col2 = temp1; 
                             else col2 = temp2;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 05 Nov 2020 00:18:07 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2020-11-05T00:18:07Z</dc:date>
    <item>
      <title>Replacing missing column variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-missing-column-variables/m-p/696650#M212818</link>
      <description>&lt;P&gt;I have the following data set:&lt;/P&gt;
&lt;P&gt;Param&amp;nbsp; &amp;nbsp;col2&amp;nbsp; treat&amp;nbsp; &amp;nbsp;subn2&lt;/P&gt;
&lt;P&gt;ka1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.41&amp;nbsp; ATES&amp;nbsp; &amp;nbsp; .&lt;/P&gt;
&lt;P&gt;ka2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1.00&amp;nbsp; ATES&amp;nbsp; &amp;nbsp; .&lt;/P&gt;
&lt;P&gt;ka1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&amp;nbsp; &amp;nbsp; &amp;nbsp;BREF&amp;nbsp; &amp;nbsp;0.64&lt;/P&gt;
&lt;P&gt;ka2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&amp;nbsp; &amp;nbsp; &amp;nbsp;BREF&amp;nbsp; 1.00&lt;/P&gt;
&lt;P&gt;The data set has missing values for ka1 and ka2 for subn2.&amp;nbsp; What I want to do is to replace the missing ka1 and ka2 values in subn2 with the values ka1 and ka2 values under col2. I tried the inserted SAS code.&amp;nbsp; I got the following syntax error in the log.&lt;/P&gt;
&lt;P&gt;I think that my logic is okay but it may not be.&amp;nbsp; Can someone tell me if my logic seems okay and if so how do I correct the syntax error and if the logic is faulty what would be better?&lt;/P&gt;
&lt;P&gt;LOG in&amp;nbsp;&lt;/P&gt;
&lt;P&gt;[Data new;&lt;BR /&gt;482 set Xall_final10_2;&lt;BR /&gt;483 retain temp1 temp2;&lt;BR /&gt;484 if ka1 in (col2 ne.) then temp1=ka1;&lt;BR /&gt;____&lt;BR /&gt;22&lt;BR /&gt;76&lt;BR /&gt;485 if ka2 in (col2 ne.) then temp2=ka2;&lt;BR /&gt;____&lt;BR /&gt;22&lt;BR /&gt;76&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: a quoted string, a numeric constant, a datetime constant, &lt;BR /&gt;a missing value, iterator, (.&lt;/P&gt;
&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
Data new;
set Xall_final10_2;
retain temp1 temp2;
if ka1 in (col2 ne.) then temp1=ka1;
if ka2 in (col2 ne.) then temp2=ka2;

if ka1 in (subn2=.) then ka1=temp1;
if ka2 in (subn2=.)  then ka2=temp2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Nov 2020 19:36:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-missing-column-variables/m-p/696650#M212818</guid>
      <dc:creator>jacksonan123</dc:creator>
      <dc:date>2020-11-04T19:36:04Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing missing column variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-missing-column-variables/m-p/696662#M212823</link>
      <description>&lt;P&gt;The IN operator requires a list of values. No functions, no variable names, no operations, just values:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if numeric something like:&lt;/P&gt;
&lt;P&gt;if x in ( 1 2 3).&lt;/P&gt;
&lt;P&gt;If the comparison is character the values are in quotes&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;in name in ('Fred' 'John' 'Mary')&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;in ( col2 ne .) violates two of the rules, Col2 is apparently a variable and "ne" is a comparison operation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please provide data in a useable form, like a data step. You do not show a "missing Ka1" and values of ka1 are not "under col2".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to test if a variable has a missing value easiest is:&amp;nbsp;&amp;nbsp; missing(variablename) which returns a numeric 1/0 for "true" or "false"&lt;/P&gt;</description>
      <pubDate>Wed, 04 Nov 2020 19:55:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-missing-column-variables/m-p/696662#M212823</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-11-04T19:55:52Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing missing column variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-missing-column-variables/m-p/696665#M212825</link>
      <description>&lt;P&gt;The combination of&amp;nbsp;&lt;STRONG&gt; in (subn2 = )&amp;nbsp;&lt;/STRONG&gt;or&amp;nbsp;&lt;STRONG&gt;in (subn2 ne )&amp;nbsp;&lt;/STRONG&gt;is erroneous&lt;/P&gt;
&lt;P&gt;What you probably mean to do is:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if param = "ka1" and col2 ne . then temp1 = param; else 
if param = "ka2" and col2 ne . then temp2 = param; else
if col2 = . then do;
  if param = "ka1" then col2 = temp1; 
                             else col2 = temp2;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Nov 2020 19:57:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-missing-column-variables/m-p/696665#M212825</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-11-04T19:57:42Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing missing column variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-missing-column-variables/m-p/696706#M212849</link>
      <description>I tried your code and got the following log which indicates that ka1 is&lt;BR /&gt;being read as invalid numeric data.  Can you tell me why&lt;BR /&gt;&lt;BR /&gt;NOTE: Character values have been converted to numeric values at the places&lt;BR /&gt;given by: (Line):(Column).&lt;BR /&gt;&lt;BR /&gt;      487:30   488:13   &lt;BR /&gt;&lt;BR /&gt;NOTE: Invalid numeric data, temp1='ka1' , at line 487 column 30.&lt;BR /&gt;&lt;BR /&gt;Param=ka1 COL2=. Treat=BREF subn2=0.649437562 subj1=. subj2=1.914463759&lt;BR /&gt;subj3=. subj4=. subj5=. subj6=. subj7=. subj8=. subj9=.&lt;BR /&gt;&lt;BR /&gt;subj10=. subj11=. subj12=. subj13=. subj14=. subj15=. subj16=. subj17=.&lt;BR /&gt;subj18=. subj19=. subj20=. subj21=. subj22=. subj23=.&lt;BR /&gt;&lt;BR /&gt;subj24=. subj25=. subj26=. subj27=. subj28=. subj29=. subj30=. subj31=.&lt;BR /&gt;subj32=. subj33=. subj34=. subn1=. subn3=. subn4=. subn5=.&lt;BR /&gt;&lt;BR /&gt;subn6=. subn7=. subn8=. subn9=. subn10=. subn11=. subn12=. subn13=. subn14=.&lt;BR /&gt;subn15=. subn16=. subn17=. subn18=. subn19=. subn20=.&lt;BR /&gt;&lt;BR /&gt;subn21=. subn22=. subn23=. subn24=. subn25=. subn26=. subn27=. subn28=.&lt;BR /&gt;subn29=. subn30=. subn31=. subn32=. subn33=. subn34=. i=35&lt;BR /&gt;&lt;BR /&gt;temp1=ka1 temp2=ka2 _ERROR_=1 _N_=8&lt;BR /&gt;&lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt;I also tried to remove the double quotes "ka1" then the  log read:&lt;BR /&gt;&lt;BR /&gt;NOTE: Character values have been converted to numeric values at the places&lt;BR /&gt;given by: (Line):(Column).&lt;BR /&gt;&lt;BR /&gt;      487:28   488:13   &lt;BR /&gt;&lt;BR /&gt;NOTE: Variable ka1 is uninitialized.&lt;BR /&gt;&lt;BR /&gt;NOTE: Variable ka2 is uninitialized.&lt;BR /&gt;&lt;BR /&gt; &lt;BR /&gt;</description>
      <pubDate>Wed, 04 Nov 2020 22:21:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-missing-column-variables/m-p/696706#M212849</guid>
      <dc:creator>jacksonan123</dc:creator>
      <dc:date>2020-11-04T22:21:35Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing missing column variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-missing-column-variables/m-p/696739#M212865</link>
      <description>&lt;P&gt;Just need define temp1 and temp2 variables as char type by assigning $&amp;lt;length&amp;gt;:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data new;
set Xall_final10_2;
length temp1 temp2 $3;
retain temp1 temp2;
if param = "ka1" and col2 ne . then temp1 = param; else 
if param = "ka2" and col2 ne . then temp2 = param; else
if col2 = . then do;
  if param = "ka1" then col2 = temp1; 
                             else col2 = temp2;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Nov 2020 00:18:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-missing-column-variables/m-p/696739#M212865</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-11-05T00:18:07Z</dc:date>
    </item>
  </channel>
</rss>

