<?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: Fill missing in specific rows by groups in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Fill-missing-in-specific-rows-by-groups/m-p/645822#M193094</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA FILL; 
INPUT NAME $ I J K;
CARDS;
A 10 . .
B . 25 .
C . . 23
D 2 . .
E . . 3
F . 25 .
G 1 2 4
H 5 7 8
;


data have;
set fill;
n+1;
retain group;
if name in ('A' 'B'  'C') then group=1;
else if name in ('D' 'E' 'F') then group=2;
else group+1;
run;
data temp;
 update have(obs=0) have;
 by group;
 output;
run;
proc sort data=temp;
by group descending n;
run;
data want;
 update temp(obs=0) temp;
 by group;
 output;
run;
proc sort data=want;
by group n;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 07 May 2020 11:17:30 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2020-05-07T11:17:30Z</dc:date>
    <item>
      <title>Fill missing in specific rows by groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fill-missing-in-specific-rows-by-groups/m-p/645782#M193077</link>
      <description>&lt;P&gt;Hi Folks:&lt;/P&gt;
&lt;P&gt;I'm trying to replace missing information by existing information in the data with some conditions applied as shown in the image below. I couldn't do it manually and hope there's a way to automate this in SAS?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="FILL.png" style="width: 490px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/39149iFB1EA482FEF4DF09/image-size/large?v=v2&amp;amp;px=999" role="button" title="FILL.png" alt="FILL.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if prxmatch("m/A|B|C/oi",NAME) &amp;gt; 0 then fill missing in variable I using the
available value. Which is 10 for I, 25 for J and 23 for K variables. 
 
if prxmatch("m/D|E|F/oi",NAME) &amp;gt; 0  then fill missing in variable I using the
available value. Which is 2 for I, 25 for J and 3 for K variables. 

I have 10 more batches by prxmatch conditions as shown above. 

About 85% of data has no missing as shown by G and H rows. No action needed 
if no missing outside the rows specified in the prxmatch clauses.  &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA FILL; 
INPUT NAME $ I J K;
CARDS;
A	10	.	.
B	.	25	.
C	.	.	23
D	2	.	.
E	.	.	3
F	.	25	.
G	1	2	4
H	5	7	8
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I greatly appreciate your time and help.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 May 2020 06:20:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fill-missing-in-specific-rows-by-groups/m-p/645782#M193077</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2020-05-07T06:20:06Z</dc:date>
    </item>
    <item>
      <title>Re: Fill missing in specific rows by groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fill-missing-in-specific-rows-by-groups/m-p/645789#M193081</link>
      <description>&lt;P&gt;please try the below code, the expected output will be in i1 j1 and k1 variables&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA FILL; 
INPUT NAME $ I J K;
CARDS;
A 10 . .
B . 25 .
C . . 23
D 2 . .
E . . 3
F . 25 .
G 1 2 4
H 5 7 8
;


data have;
set fill;
retain group;
if name in ('A' 'B'  'C') then group=1;
else if name in ('D' 'E' 'F') then group=2;
else group+1;
run;

proc sort data=have;
by group name;
run;

data want;
do until(last.group);
set have;
by group;
retain i1 j1 k1;
array vars1(3) i j k;
array vars(3) i1 j1 k1;
do z = 1 to 3;
if first.group then vars(z)=.;
if vars1(z) ne . then vars(z)=vars1(z);
end;
end;
do until(last.group);
set have;
by group;
output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 May 2020 07:00:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fill-missing-in-specific-rows-by-groups/m-p/645789#M193081</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2020-05-07T07:00:16Z</dc:date>
    </item>
    <item>
      <title>Re: Fill missing in specific rows by groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fill-missing-in-specific-rows-by-groups/m-p/645795#M193084</link>
      <description>&lt;P&gt;From where do you know that A,B,C and D,E,F form a group?&lt;/P&gt;</description>
      <pubDate>Thu, 07 May 2020 07:15:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fill-missing-in-specific-rows-by-groups/m-p/645795#M193084</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-05-07T07:15:38Z</dc:date>
    </item>
    <item>
      <title>Re: Fill missing in specific rows by groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fill-missing-in-specific-rows-by-groups/m-p/645798#M193085</link>
      <description>&lt;P&gt;They are city names that are part of a province. Data I merged didn't have city-specific values but province average. That province average is recorded as one of city values. Therefore, known value of a city value (actually province average) is being used for the other cities. I can not remove them just because they're less accurate. Also, I have about 32 variables as each one of these are survey items.&amp;nbsp;&lt;SPAN&gt;Jagadishkatam would do the job but I have to create an exhaustive list of 32 variables and their index variables. Then rename and drop not needed ones et.c. Is there anyway to go around this iterative typing process?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 May 2020 07:26:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fill-missing-in-specific-rows-by-groups/m-p/645798#M193085</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2020-05-07T07:26:18Z</dc:date>
    </item>
    <item>
      <title>Re: Fill missing in specific rows by groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fill-missing-in-specific-rows-by-groups/m-p/645799#M193086</link>
      <description>&lt;P&gt;You need to have a LOGICAL RULE which can be converted into code. No rule, no code. At least not code that can be generalized. And writing every single instance into the code defeats the purpose of programming.&lt;/P&gt;
&lt;P&gt;So the first thing you need to do is set up a mechanism that assigns those groups &lt;EM&gt;automatically&lt;/EM&gt;. If you need assistance in that, post your original data (or a mock-up that so closely resembles your original data that you can translate our code suggestions).&lt;/P&gt;</description>
      <pubDate>Thu, 07 May 2020 07:32:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fill-missing-in-specific-rows-by-groups/m-p/645799#M193086</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-05-07T07:32:21Z</dc:date>
    </item>
    <item>
      <title>Re: Fill missing in specific rows by groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fill-missing-in-specific-rows-by-groups/m-p/645802#M193088</link>
      <description>&lt;P&gt;creating mock data? i'll work on that tomorrow. but i still believe that there is a logic and problem could be solved based on the small mock data I posted assuming that I have many columns about N=32.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 May 2020 07:59:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fill-missing-in-specific-rows-by-groups/m-p/645802#M193088</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2020-05-07T07:59:47Z</dc:date>
    </item>
    <item>
      <title>Re: Fill missing in specific rows by groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fill-missing-in-specific-rows-by-groups/m-p/645803#M193089</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12151"&gt;@Jagadishkatam&lt;/a&gt;'s suggestion will work for the data you posted, BUT FOR NOTHING ELSE! Just read that code, it does the grouping with literal values in the code, and this part HAS TO BE REPLACED with something that automates this, or you'll be writing code for every city you encounter.&lt;/P&gt;</description>
      <pubDate>Thu, 07 May 2020 08:19:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fill-missing-in-specific-rows-by-groups/m-p/645803#M193089</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-05-07T08:19:58Z</dc:date>
    </item>
    <item>
      <title>Re: Fill missing in specific rows by groups</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Fill-missing-in-specific-rows-by-groups/m-p/645822#M193094</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA FILL; 
INPUT NAME $ I J K;
CARDS;
A 10 . .
B . 25 .
C . . 23
D 2 . .
E . . 3
F . 25 .
G 1 2 4
H 5 7 8
;


data have;
set fill;
n+1;
retain group;
if name in ('A' 'B'  'C') then group=1;
else if name in ('D' 'E' 'F') then group=2;
else group+1;
run;
data temp;
 update have(obs=0) have;
 by group;
 output;
run;
proc sort data=temp;
by group descending n;
run;
data want;
 update temp(obs=0) temp;
 by group;
 output;
run;
proc sort data=want;
by group n;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 May 2020 11:17:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Fill-missing-in-specific-rows-by-groups/m-p/645822#M193094</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-05-07T11:17:30Z</dc:date>
    </item>
  </channel>
</rss>

