<?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 new var by 1st valid value of another var for all records of the same custome in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Assign-values-to-a-new-var-by-1st-valid-value-of-another-var-for/m-p/767469#M243319</link>
    <description>&lt;P&gt;Please try&amp;nbsp;&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
4  
4  
4 C
4 D
4 D
4 C
;
run;

data first;
set have;
by Customer_ID;
where Customer_Cat ne '';
if first.Customer_ID;
Derived_Customer_Cat =Customer_Cat;
keep Customer_ID Derived_Customer_Cat;
run;

data want2;
merge have(in=a) first(in=b) ;
by Customer_ID;
if a;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 13 Sep 2021 16:24:22 GMT</pubDate>
    <dc:creator>Jagadishkatam</dc:creator>
    <dc:date>2021-09-13T16:24:22Z</dc:date>
    <item>
      <title>Assign values to a new var by 1st valid value of another var for all records of the same customer</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-values-to-a-new-var-by-1st-valid-value-of-another-var-for/m-p/767427#M243297</link>
      <description>&lt;P&gt;Hi,&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 valid 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;4 &lt;BR /&gt;4 &lt;BR /&gt;4 C&lt;BR /&gt;4 D&lt;BR /&gt;4 D&lt;BR /&gt;4&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;input Customer_ID $1 Customer_Cat $3 Derived_Customer_Cat $5;&lt;BR /&gt;datalines;&lt;BR /&gt;1 A A&lt;BR /&gt;1 A A&lt;BR /&gt;1 A A&lt;BR /&gt;2 B&lt;BR /&gt;2 B B&lt;BR /&gt;2 B B&lt;BR /&gt;3 A&lt;BR /&gt;3 A&lt;BR /&gt;3 A A&lt;BR /&gt;3 C A&lt;BR /&gt;4 C&lt;BR /&gt;4 C&lt;BR /&gt;4 C C&lt;BR /&gt;4 D C&lt;BR /&gt;4 D C&lt;BR /&gt;4 C&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Sep 2021 14:28:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-values-to-a-new-var-by-1st-valid-value-of-another-var-for/m-p/767427#M243297</guid>
      <dc:creator>JasonL</dc:creator>
      <dc:date>2021-09-13T14:28:08Z</dc:date>
    </item>
    <item>
      <title>Re: Assign values to a new var by 1st valid value of another var for all records of the same custome</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-values-to-a-new-var-by-1st-valid-value-of-another-var-for/m-p/767429#M243298</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;...&amp;nbsp;&lt;SPAN&gt;based on the first valid value&amp;nbsp;...&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;What is a "valid value"?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Sep 2021 14:33:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-values-to-a-new-var-by-1st-valid-value-of-another-var-for/m-p/767429#M243298</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-09-13T14:33:16Z</dc:date>
    </item>
    <item>
      <title>Re: Assign values to a new var by 1st valid value of another var for all records of the same custome</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-values-to-a-new-var-by-1st-valid-value-of-another-var-for/m-p/767438#M243302</link>
      <description>&lt;P&gt;I should have said "non-missing" value.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Sep 2021 15:12:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-values-to-a-new-var-by-1st-valid-value-of-another-var-for/m-p/767438#M243302</guid>
      <dc:creator>JasonL</dc:creator>
      <dc:date>2021-09-13T15:12:21Z</dc:date>
    </item>
    <item>
      <title>Re: Assign values to a new var by 1st valid value of another var for all records of the same custome</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-values-to-a-new-var-by-1st-valid-value-of-another-var-for/m-p/767440#M243303</link>
      <description>&lt;P&gt;Sorry the datalines for "want" got shifted.&amp;nbsp; And here is what the data steps should be:&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;4 &lt;BR /&gt;4 &lt;BR /&gt;4 C&lt;BR /&gt;4 D&lt;BR /&gt;4 D&lt;BR /&gt;4&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;input Customer_ID $1 Customer_Cat $3 Derived_Customer_Cat $5;&lt;BR /&gt;datalines;&lt;BR /&gt;1 A A&lt;BR /&gt;1 A A&lt;BR /&gt;1 A A&lt;BR /&gt;2&amp;nbsp; &amp;nbsp; B&lt;BR /&gt;2 B B&lt;BR /&gt;2 B B&lt;BR /&gt;3&amp;nbsp; &amp;nbsp; A&lt;BR /&gt;3&amp;nbsp; &amp;nbsp; A&lt;BR /&gt;3 A A&lt;BR /&gt;3 C A&lt;BR /&gt;4&amp;nbsp; &amp;nbsp; C&lt;BR /&gt;4&amp;nbsp; &amp;nbsp; C&lt;BR /&gt;4 C C&lt;BR /&gt;4 D C&lt;BR /&gt;4 D C&lt;BR /&gt;4 C C&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Sep 2021 15:16:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-values-to-a-new-var-by-1st-valid-value-of-another-var-for/m-p/767440#M243303</guid>
      <dc:creator>JasonL</dc:creator>
      <dc:date>2021-09-13T15:16:50Z</dc:date>
    </item>
    <item>
      <title>Re: Assign values to a new var by 1st valid value of another var for all records of the same custome</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-values-to-a-new-var-by-1st-valid-value-of-another-var-for/m-p/767469#M243319</link>
      <description>&lt;P&gt;Please try&amp;nbsp;&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
4  
4  
4 C
4 D
4 D
4 C
;
run;

data first;
set have;
by Customer_ID;
where Customer_Cat ne '';
if first.Customer_ID;
Derived_Customer_Cat =Customer_Cat;
keep Customer_ID Derived_Customer_Cat;
run;

data want2;
merge have(in=a) first(in=b) ;
by Customer_ID;
if a;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Sep 2021 16:24:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-values-to-a-new-var-by-1st-valid-value-of-another-var-for/m-p/767469#M243319</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2021-09-13T16:24:22Z</dc:date>
    </item>
    <item>
      <title>Re: Assign values to a new var by 1st valid value of another var for all records of the same custome</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-values-to-a-new-var-by-1st-valid-value-of-another-var-for/m-p/767472#M243321</link>
      <description>&lt;P&gt;Thank you!&amp;nbsp; This works.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Sep 2021 16:29:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-values-to-a-new-var-by-1st-valid-value-of-another-var-for/m-p/767472#M243321</guid>
      <dc:creator>JasonL</dc:creator>
      <dc:date>2021-09-13T16:29:05Z</dc:date>
    </item>
  </channel>
</rss>

