<?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: Change value for columns based on other observations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Change-value-for-columns-based-on-other-observations/m-p/635503#M188698</link>
    <description>&lt;P&gt;It is probably more efficient to run a data step first to determine the columns to be set missing, e.g.:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let nullvars=; /* no variables found yet */
data _null_;
  set have;
  length nullvars $200;
  array vars b--g;
  do _N_=1 to dim(vars);
    if not vars(_N_) then
      call catx(',',nullvars,vname(vars(_N_));
    end;
  if lengthn(nullvars) then
    call symputx('nullvars',catx('call missing(',nullvars,')');
  stop;
run;

data want;
  set have;
  &amp;amp;nullvars;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 28 Mar 2020 13:38:24 GMT</pubDate>
    <dc:creator>s_lassen</dc:creator>
    <dc:date>2020-03-28T13:38:24Z</dc:date>
    <item>
      <title>Change value for columns based on other observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-value-for-columns-based-on-other-observations/m-p/635476#M188684</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;I need to keep entire column blank if observation#1 is missing or 0 .&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please do needful.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x;
infile datalines missover;
 input b c  d e f g  ;
 datalines;
 0 1 0 1 0   
 1 2 5 7 9 1 
 ;

 data xx;
  set x;
  array all(*) b c d e f g;
  do i = 1 to dim(all);
  if _n_=1 and all(i) in (0,.) then do;
   all(i)=.;
   if _n_ &amp;gt; 1 then all(i)=.;
  end;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 28 Mar 2020 07:37:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-value-for-columns-based-on-other-observations/m-p/635476#M188684</guid>
      <dc:creator>draroda</dc:creator>
      <dc:date>2020-03-28T07:37:17Z</dc:date>
    </item>
    <item>
      <title>Re: Change value for columns based on other observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-value-for-columns-based-on-other-observations/m-p/635484#M188692</link>
      <description>&lt;P&gt;Consider:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/44091"&gt;@draroda&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;I need to keep entire column blank if observation#1 is missing or 0 .&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please do needful.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x;
infile datalines missover;
 input b c  d e f g  ;
 datalines;
 0 1 0 1 0   
 1 2 5 7 9 1 
 ;

 data xx;
  set x;
  array all(*) b c d e f g;
  do i = 1 to dim(all);
  if _n_=1 and all(i) in (0,.) then do;
   all(i)=.;
   if _n_ &amp;gt; 1 then all(i)=.;
  end;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;One way is to have the first values from the set. The RETAIN creates a set of variables that the values will be kept from observation to observation. Then they are only populated for the first record.&amp;nbsp; Place them into an array for handy reference.&lt;/P&gt;
&lt;P&gt;After satisfied that the logic works you could use : Drop f_: ; to remove all the temporary variables from your data. The colon creates a list of all variables whose names start with f_ .&lt;/P&gt;</description>
      <pubDate>Sat, 28 Mar 2020 09:11:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-value-for-columns-based-on-other-observations/m-p/635484#M188692</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-03-28T09:11:25Z</dc:date>
    </item>
    <item>
      <title>Re: Change value for columns based on other observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-value-for-columns-based-on-other-observations/m-p/635489#M188695</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; data xx;
  set x;
  array all  [6] b -- g;
  array first[6] _temporary_;
  do i = 1 to dim(all);
    if _n_=1 then first[i] = all[i]; 
    if not first[i] then all[i]=.;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 28 Mar 2020 10:28:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-value-for-columns-based-on-other-observations/m-p/635489#M188695</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-03-28T10:28:48Z</dc:date>
    </item>
    <item>
      <title>Re: Change value for columns based on other observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-value-for-columns-based-on-other-observations/m-p/635503#M188698</link>
      <description>&lt;P&gt;It is probably more efficient to run a data step first to determine the columns to be set missing, e.g.:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let nullvars=; /* no variables found yet */
data _null_;
  set have;
  length nullvars $200;
  array vars b--g;
  do _N_=1 to dim(vars);
    if not vars(_N_) then
      call catx(',',nullvars,vname(vars(_N_));
    end;
  if lengthn(nullvars) then
    call symputx('nullvars',catx('call missing(',nullvars,')');
  stop;
run;

data want;
  set have;
  &amp;amp;nullvars;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 28 Mar 2020 13:38:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-value-for-columns-based-on-other-observations/m-p/635503#M188698</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-03-28T13:38:24Z</dc:date>
    </item>
    <item>
      <title>Re: Change value for columns based on other observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-value-for-columns-based-on-other-observations/m-p/635506#M188700</link>
      <description>&lt;P&gt;Do a transpose of the first observation, and use SQL to create the variable list for call missing:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x;
infile datalines missover;
input b c  d e f g  ;
datalines;
0 1 0 1 0   
1 2 5 7 9 1 
;

proc transpose data=x (obs=1) out=trans (where=(col1=.));
var _numeric_;
run;

proc sql noprint;
select _name_ into :names separated by ',' from trans;
quit;

data want;
set x;
call missing(&amp;amp;names);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 28 Mar 2020 13:54:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-value-for-columns-based-on-other-observations/m-p/635506#M188700</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-03-28T13:54:06Z</dc:date>
    </item>
    <item>
      <title>Re: Change value for columns based on other observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-value-for-columns-based-on-other-observations/m-p/635615#M188751</link>
      <description>Basically the same solution as my suggestion. With one exception: if there are no missing or zero values in the first row, the statement "CALL MISSING();" will be executed, which I think will provoke an error.</description>
      <pubDate>Sun, 29 Mar 2020 11:09:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-value-for-columns-based-on-other-observations/m-p/635615#M188751</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-03-29T11:09:40Z</dc:date>
    </item>
    <item>
      <title>Re: Change value for columns based on other observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-value-for-columns-based-on-other-observations/m-p/635647#M188760</link>
      <description>&lt;P&gt;Yep, we need to safeguard against that:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x;
infile datalines missover;
input b c  d e f g  ;
datalines;
0 1 0 1 0 2 
1 2 5 7 9 1 
;

proc transpose data=x (obs=1) out=trans (where=(col1=.));
var _numeric_;
run;

%let names=;
proc sql noprint;
select _name_ into :names separated by ',' from trans;
quit;

%if &amp;amp;names. &amp;gt; %then %do;
data want;
set x;
call missing(&amp;amp;names);
run;
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thanks to SAS for making %if %then %do - %end available in open code.&lt;/P&gt;</description>
      <pubDate>Sun, 29 Mar 2020 15:06:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-value-for-columns-based-on-other-observations/m-p/635647#M188760</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-03-29T15:06:21Z</dc:date>
    </item>
  </channel>
</rss>

