<?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: Assign values to a var by 1st non-missing value of another var for all records of the same custo in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Assign-values-to-a-var-by-1st-non-missing-value-of-another-var/m-p/767487#M243327</link>
    <description>&lt;P&gt;Here is one solution but this isn't the only way to do it. I find first non-missing value of customer_cat and rename it to derived_customer_cat and merge that dataset back with the have dataset. It gets your desired results.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have; 
	by customer_id;
run;

data want(rename=(customer_cat=derived_customer_cat));
	set have;
	by customer_id;
	where ^missing(customer_cat);
	if first.customer_id;
run;

data merged;
	merge have(in=a) want;
	by customer_id;
	if a;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 13 Sep 2021 17:04:36 GMT</pubDate>
    <dc:creator>tarheel13</dc:creator>
    <dc:date>2021-09-13T17:04:36Z</dc:date>
    <item>
      <title>Assign values to a var by 1st non-missing value of another var for all records of the same customer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-values-to-a-var-by-1st-non-missing-value-of-another-var/m-p/767444#M243304</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(I posted a similar request a few minutes ago, but the datalines in that one got shifted when pasted here.&amp;nbsp; And here it is again.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to assign a customer category in a new variable (Derived_Customer_Cat) to each customer record based on the first non-missing value of a variable (Customer_Cat) for all records of the same customer (Customer_ID).&amp;nbsp; And the following code is a demonstration of what I have and want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you help me find an efficient approach?&amp;nbsp; Thank you!&lt;/P&gt;
&lt;P&gt;Jason&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;input Customer_ID $1 Customer_Cat $3;&lt;BR /&gt;datalines;&lt;BR /&gt;1 A&lt;BR /&gt;1 A&lt;BR /&gt;1 A&lt;BR /&gt;2&lt;BR /&gt;2 B&lt;BR /&gt;2 B&lt;BR /&gt;3&lt;BR /&gt;3&lt;BR /&gt;3 A&lt;BR /&gt;3 C&lt;BR /&gt;3&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;data want;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;input Customer_ID $1 Customer_Cat $3 Derived_Customer_Cat $5;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;datalines;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 A A&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 A A&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 A A&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2&amp;nbsp; &amp;nbsp;B&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2 B B&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2 B B&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3&amp;nbsp; &amp;nbsp;A&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3&amp;nbsp; &amp;nbsp;A&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3 A A&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3 C A&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3&amp;nbsp; &amp;nbsp;A&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Sep 2021 15:28:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-values-to-a-var-by-1st-non-missing-value-of-another-var/m-p/767444#M243304</guid>
      <dc:creator>JasonL</dc:creator>
      <dc:date>2021-09-13T15:28:23Z</dc:date>
    </item>
    <item>
      <title>Re: Assign values to a var by 1st non-missing value of another var for all records of the same custo</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-values-to-a-var-by-1st-non-missing-value-of-another-var/m-p/767450#M243308</link>
      <description>&lt;P&gt;Paste code and log entries is either a text box, opened using the &amp;lt;/&amp;gt; icon or code box opened with the "running man" icon that appears above the message window. That way the text doesn't "get shifted". The message windows here will reformat text so one of those boxes is the way to preserve things.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Sep 2021 15:43:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-values-to-a-var-by-1st-non-missing-value-of-another-var/m-p/767450#M243308</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-09-13T15:43:39Z</dc:date>
    </item>
    <item>
      <title>Re: Assign values to a var by 1st non-missing value of another var for all records of the same custo</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-values-to-a-var-by-1st-non-missing-value-of-another-var/m-p/767454#M243310</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks to ballardw, here is the properly pasted code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Customer_ID $1 Customer_Cat $3;
datalines;
1 A
1 A
1 A
2 
2 B
2 B
3 
3 
3 A
3 C
3
;
run;

data want;
input Customer_ID $1 Customer_Cat $3 Derived_Customer_Cat $5;
datalines;
1 A A
1 A A
1 A A
2   B
2 B B
2 B B
3   A
3   A
3 A A
3 C A
3   A
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Sep 2021 15:48:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-values-to-a-var-by-1st-non-missing-value-of-another-var/m-p/767454#M243310</guid>
      <dc:creator>JasonL</dc:creator>
      <dc:date>2021-09-13T15:48:53Z</dc:date>
    </item>
    <item>
      <title>Re: Assign values to a var by 1st non-missing value of another var for all records of the same custo</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-values-to-a-var-by-1st-non-missing-value-of-another-var/m-p/767487#M243327</link>
      <description>&lt;P&gt;Here is one solution but this isn't the only way to do it. I find first non-missing value of customer_cat and rename it to derived_customer_cat and merge that dataset back with the have dataset. It gets your desired results.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have; 
	by customer_id;
run;

data want(rename=(customer_cat=derived_customer_cat));
	set have;
	by customer_id;
	where ^missing(customer_cat);
	if first.customer_id;
run;

data merged;
	merge have(in=a) want;
	by customer_id;
	if a;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Sep 2021 17:04:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-values-to-a-var-by-1st-non-missing-value-of-another-var/m-p/767487#M243327</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2021-09-13T17:04:36Z</dc:date>
    </item>
    <item>
      <title>Re: Assign values to a var by 1st non-missing value of another var for all records of the same custo</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-values-to-a-var-by-1st-non-missing-value-of-another-var/m-p/767548#M243355</link>
      <description>&lt;P&gt;Thank you&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A class="trigger-hovercard" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/181158" target="_blank"&gt;lrackley&lt;/A&gt;!&amp;nbsp; This works.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Sep 2021 20:25:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-values-to-a-var-by-1st-non-missing-value-of-another-var/m-p/767548#M243355</guid>
      <dc:creator>JasonL</dc:creator>
      <dc:date>2021-09-13T20:25:09Z</dc:date>
    </item>
  </channel>
</rss>

