<?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: Creation of new column values with respect to multiple column values. in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Creation-of-new-column-values-with-respect-to-multiple-column/m-p/635165#M21281</link>
    <description>&lt;P&gt;LAG() implies there is some type of order to the observations. What order you want the observations to be processed in? The original dataset DS1 did not have any order variable. Once it is sorted by NAME to enable merging the original order is gone. Do you have some other order variable?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also is the real data grouped in anyway? Is there some other variable that groups the data. When using LAG() you do not want to "lag" a value across group boundaries. You don't want the first observations for the new group to see the last value from the old group.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;it is not clear what you mean by "one value from col3".&amp;nbsp; The COL3 variable only ever has one value per observation. Just as the NEW_VAR will only ever have one value per observation.&amp;nbsp; Why did you eliminate two of the observations?&amp;nbsp; Perhaps you want to collapse to only one observation per group?&amp;nbsp; Again, is there some type of grouping variable?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 26 Mar 2020 22:29:27 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2020-03-26T22:29:27Z</dc:date>
    <item>
      <title>Creation of new column values with respect to multiple column values.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creation-of-new-column-values-with-respect-to-multiple-column/m-p/635041#M21269</link>
      <description>&lt;P&gt;Hello everyone,&lt;BR /&gt;Thank you for taking your time to read this question!&lt;/P&gt;&lt;P&gt;I would like to create a variable if some conditions are satisfied by other variables.&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example:&lt;/P&gt;&lt;P&gt;DS-1 dataset checks for 'name' values in 'col-2' values and then if the value is found then 'col-3' gets 'name' values&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;DS-1&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;name&amp;nbsp; &amp;nbsp; &amp;nbsp; col-2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;col-3&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Y&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Y,H,J&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Y&lt;/P&gt;&lt;P&gt;Z&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;H,K,R&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;C&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Y,C,Z&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;C&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DS-2 dataset is like a lookup table, it has desired 'name' values along with their respective 'id' values. Plz note that the&amp;nbsp;&lt;/P&gt;&lt;P&gt;'id' column's order is important.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;DS-2&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;name&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;id&lt;/P&gt;&lt;P&gt;Y&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;C&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;Z&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DS-3 dataset is the output dataset based on some conditions.&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;It conditionally compares&amp;nbsp; DS-1 and DS-2.&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;conditionally means- if 'id' value (1) 's 'name' value(Y) is present in DS-1 then DS-3 will have 'Y'&amp;nbsp; &lt;STRONG&gt;AS DISPLAYED IN DS-3 DATASET&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI&gt;if 'id' value (1) 's 'name' value(Y) is NOT present in DS-1 then it checks for the next 'id' value(2)'s 'name' value(c) in DS-1.&lt;/LI&gt;&lt;LI&gt;it continues to do this conditional check for all&amp;nbsp; 'id' values until it finds one. If it doesnt find any then 'col_new' will be empty value.&lt;/LI&gt;&lt;LI&gt;So, it checks chronologically and if any value is found then it stops and does not check for the rest of it.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;DS-3 (desired output)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;col_new&lt;/P&gt;&lt;P&gt;Y&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could some one please help me code this logic? If my explanation needs to be rephrased; please do let me know.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for taking your time to read my question!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Mar 2020 13:21:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creation-of-new-column-values-with-respect-to-multiple-column/m-p/635041#M21269</guid>
      <dc:creator>Saser_123</dc:creator>
      <dc:date>2020-03-26T13:21:52Z</dc:date>
    </item>
    <item>
      <title>Re: Creation of new column values with respect to multiple column values.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creation-of-new-column-values-with-respect-to-multiple-column/m-p/635061#M21271</link>
      <description>&lt;P&gt;I have tried a couple of ways using "first. and last.", "select- when", "case-when", and "if- then-else". Below&amp;nbsp;&lt;BR /&gt;sample code that did not work properly. I am willing to take a total new approach if needed.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thanks again!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ds-3;
set ds-1 ds-2;
select(id);
  when(1) do;
    if length(col_3) ne 0 then col_new = col_3;
    else col_3 = "";
    end;
  when(2) do;
    if ( length(col_3) ne 0 ) and (lag(length(col_new) eq 0))) then col_new  = col_3; /* lag is used to check if the previous obs of col_new is empty or not */
     end;
 when(3) do;
    if ( length(col_3) ne 0 ) and (lag(length(col_new) eq 0))) then col_new  = col_3;
     end;
otherwise col_new = "";
end;
run;


&amp;nbsp;&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Mar 2020 15:35:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creation-of-new-column-values-with-respect-to-multiple-column/m-p/635061#M21271</guid>
      <dc:creator>Saser_123</dc:creator>
      <dc:date>2020-03-26T15:35:35Z</dc:date>
    </item>
    <item>
      <title>Re: Creation of new column values with respect to multiple column values.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creation-of-new-column-values-with-respect-to-multiple-column/m-p/635067#M21274</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/318742"&gt;@Saser_123&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello everyone,&lt;BR /&gt;Thank you for taking your time to read this question!&lt;/P&gt;
&lt;P&gt;I would like to create a variable if some conditions are satisfied by other variables.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;P&gt;DS-1 dataset checks for 'name' values in 'col-2' values and then if the value is found then 'col-3' gets 'name' values&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;DS-1&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;name&amp;nbsp; &amp;nbsp; &amp;nbsp; col-2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;col-3&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Y&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Y,H,J&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Y&lt;/P&gt;
&lt;P&gt;Z&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;H,K,R&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;C&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Y,C,Z&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;C&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DS-2 dataset is like a lookup table, it has desired 'name' values along with their respective 'id' values. Plz note that the&amp;nbsp;&lt;/P&gt;
&lt;P&gt;'id' column's order is important.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;DS-2&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;name&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;id&lt;/P&gt;
&lt;P&gt;Y&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;C&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;
&lt;P&gt;Z&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DS-3 dataset is the output dataset based on some conditions.&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;It conditionally compares&amp;nbsp; DS-1 and DS-2.&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;conditionally means- if 'id' value (1) 's 'name' value(Y) is present in DS-1 then DS-3 will have 'Y'&amp;nbsp; &lt;STRONG&gt;AS DISPLAYED IN DS-3 DATASET&lt;/STRONG&gt;&lt;/LI&gt;
&lt;LI&gt;if 'id' value (1) 's 'name' value(Y) is NOT present in DS-1 then it checks for the next 'id' value(2)'s 'name' value(c) in DS-1.&lt;/LI&gt;
&lt;LI&gt;it continues to do this conditional check for all&amp;nbsp; 'id' values until it finds one. If it doesnt find any then 'col_new' will be empty value.&lt;/LI&gt;
&lt;LI&gt;So, it checks chronologically and if any value is found then it stops and does not check for the rest of it.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&lt;STRONG&gt;DS-3 (desired output)&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;col_new&lt;/P&gt;
&lt;P&gt;Y&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could some one please help me code this logic? If my explanation needs to be rephrased; please do let me know.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for taking your time to read my question!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Since every single example of your DS2 data set has a corresponding name in DS1 then you appear to missing at least one rule. Probably involving col_3 because you create the variable but then do not use it in any rule.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Mar 2020 15:53:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creation-of-new-column-values-with-respect-to-multiple-column/m-p/635067#M21274</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-03-26T15:53:00Z</dc:date>
    </item>
    <item>
      <title>Re: Creation of new column values with respect to multiple column values.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creation-of-new-column-values-with-respect-to-multiple-column/m-p/635124#M21277</link>
      <description>&lt;P&gt;Thank you Ballardw for your reply.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Regarding col_3:- The part that I had mentioned before&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;&lt;U&gt;&lt;EM&gt;conditionally means- if 'id' value (1) 's 'name' value(Y) is present in DS-1 then DS-3 will have 'Y'&amp;nbsp;&lt;/EM&gt;&lt;/U&gt;&lt;/STRONG&gt;&amp;nbsp; &amp;nbsp; is done comparing "&lt;STRONG&gt;col_3&lt;/STRONG&gt;" from &lt;STRONG&gt;DS-1&lt;/STRONG&gt; value with "&lt;STRONG&gt;name&lt;/STRONG&gt;' and 'id' in &lt;STRONG&gt;DS-3.&amp;nbsp;&lt;/STRONG&gt;Hope I answered your question.&lt;BR /&gt;Ballardw, The situation I have is I have to select only &lt;STRONG&gt;one&lt;/STRONG&gt; value from "col_3" in DS-1. The selection criteria is from '&lt;STRONG&gt;id&lt;/STRONG&gt;' in &lt;STRONG&gt;DS-2&lt;/STRONG&gt;.&amp;nbsp; If '&lt;STRONG&gt;id&lt;/STRONG&gt;' is 1 and its corresponding '&lt;STRONG&gt;name&lt;/STRONG&gt;' is present in '&lt;STRONG&gt;col_3&lt;/STRONG&gt;' . Then I use that for '&lt;STRONG&gt;col_new&lt;/STRONG&gt;'. If '&lt;STRONG&gt;id&lt;/STRONG&gt;' (1) has no matching '&lt;STRONG&gt;name&lt;/STRONG&gt;" value in '&lt;STRONG&gt;col_3'&lt;/STRONG&gt;, then I go and check for&amp;nbsp; '&lt;STRONG&gt;id&lt;/STRONG&gt;' (2).....till any '&lt;STRONG&gt;id&lt;/STRONG&gt;' value mach. If nothing matches then I just leave '&lt;STRONG&gt;col_new&lt;/STRONG&gt;' blank.&lt;/P&gt;&lt;P&gt;Does that explanation help you? If not please let me know I could rephrase it&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Thu, 26 Mar 2020 19:00:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creation-of-new-column-values-with-respect-to-multiple-column/m-p/635124#M21277</guid>
      <dc:creator>Saser_123</dc:creator>
      <dc:date>2020-03-26T19:00:25Z</dc:date>
    </item>
    <item>
      <title>Re: Creation of new column values with respect to multiple column values.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creation-of-new-column-values-with-respect-to-multiple-column/m-p/635130#M21279</link>
      <description>&lt;P&gt;Your are not explaining what you mean.&amp;nbsp; You show two datasets. If you want code to operate on values that are sourced from the two datasets you need to combine them somehow first.&amp;nbsp; Are you saying that they should be combined two NAME variables have the same values?&lt;/P&gt;
&lt;P&gt;Let's try it with your example data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ds1;
  input name $  col2 $ col3 $ ;
cards;
Y           Y,H,J          Y
Z           H,K,R          .
C          Y,C,Z           C  
;
 
data ds2;
  input name $ id ;
cards;
Y                1
C                2
Z                3
;

proc sort data=ds1; by name; run;
proc sort data=ds2; by name; run;
data step1;
  merge ds1 ds2;
  by name;
run;
proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So we get this:&lt;/P&gt;
&lt;PRE&gt;Obs    name    col2     col3    id

 1      C      Y,C,Z     C       2
 2      Y      Y,H,J     Y       1
 3      Z      H,K,R             3&lt;/PRE&gt;
&lt;P&gt;Now how do you get from this dataset STEP1 to what you want as the output?&amp;nbsp; It appears you only want the row where NAME='Y'.&amp;nbsp; Why?&amp;nbsp; Why not the row where NAME='C' or NAME='Z'?&lt;/P&gt;</description>
      <pubDate>Thu, 26 Mar 2020 19:32:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creation-of-new-column-values-with-respect-to-multiple-column/m-p/635130#M21279</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-03-26T19:32:50Z</dc:date>
    </item>
    <item>
      <title>Re: Creation of new column values with respect to multiple column values.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creation-of-new-column-values-with-respect-to-multiple-column/m-p/635151#M21280</link>
      <description>&lt;P&gt;Hi Tom,&lt;BR /&gt;You are correct, there was an intermediate step( joining the two datasets)&amp;nbsp; that I did not mention. Thank you for mentioning that. So from the dataset "step1" I would like to get the values of 'name' based on values in 'id'. something like the below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;if ((id =1) and (length(col3 ne 0)) ) then new_var = col3&lt;/STRONG&gt; /&lt;EM&gt;* length(col3...) is to make sure it is not empty) */&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;else if ((id = 2) and length(col3 ne 0) and (lag(new_var) ne 0)))&amp;nbsp;&amp;nbsp;then new_var = col3&lt;/STRONG&gt; /&lt;EM&gt;* lag(new_var) to make sure that&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;the previous value of&amp;nbsp; new_var is not empty */&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;else if ((id = 3) and length(col3 ne 0) and (lag(new_var) ne 0)))&amp;nbsp;&amp;nbsp;then new_var = col3&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;so&amp;nbsp; based on the above conditions new_var will take only one value from&amp;nbsp; col3...&lt;BR /&gt;Does the above explanation make sense? if not, please do let me know I could rephrase it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;</description>
      <pubDate>Thu, 26 Mar 2020 21:35:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creation-of-new-column-values-with-respect-to-multiple-column/m-p/635151#M21280</guid>
      <dc:creator>Saser_123</dc:creator>
      <dc:date>2020-03-26T21:35:34Z</dc:date>
    </item>
    <item>
      <title>Re: Creation of new column values with respect to multiple column values.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creation-of-new-column-values-with-respect-to-multiple-column/m-p/635165#M21281</link>
      <description>&lt;P&gt;LAG() implies there is some type of order to the observations. What order you want the observations to be processed in? The original dataset DS1 did not have any order variable. Once it is sorted by NAME to enable merging the original order is gone. Do you have some other order variable?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also is the real data grouped in anyway? Is there some other variable that groups the data. When using LAG() you do not want to "lag" a value across group boundaries. You don't want the first observations for the new group to see the last value from the old group.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;it is not clear what you mean by "one value from col3".&amp;nbsp; The COL3 variable only ever has one value per observation. Just as the NEW_VAR will only ever have one value per observation.&amp;nbsp; Why did you eliminate two of the observations?&amp;nbsp; Perhaps you want to collapse to only one observation per group?&amp;nbsp; Again, is there some type of grouping variable?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Mar 2020 22:29:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creation-of-new-column-values-with-respect-to-multiple-column/m-p/635165#M21281</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-03-26T22:29:27Z</dc:date>
    </item>
    <item>
      <title>Re: Creation of new column values with respect to multiple column values.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creation-of-new-column-values-with-respect-to-multiple-column/m-p/635172#M21284</link>
      <description>&lt;P&gt;Thank you Tom for your quick response!&lt;/P&gt;&lt;P&gt;I may have used lag() incorrectly. This is the first time I am using it. I thought it will sort of retain the value of the previous observation in the current observation to do some analysis. I will have to read more on lag().&amp;nbsp;&lt;/P&gt;&lt;P&gt;lets start fresh...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Obs    name    col2     col3    id

 1      C      Y,C,Z     C       2
 2      Y      Y,H,J     Y       1
 3      Z      H,K,R             3&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;from the above dataset I want to create a new variable 'new_var' that will have the value of 'col_3'... if:&lt;/P&gt;&lt;P&gt;1) &lt;STRONG&gt;id&lt;/STRONG&gt; = 1 then &lt;STRONG&gt;new_var&lt;/STRONG&gt; = y&lt;/P&gt;&lt;P&gt;2) say &lt;STRONG&gt;id&lt;/STRONG&gt;=1 's respective &lt;STRONG&gt;col3&lt;/STRONG&gt; value is blank, then only then, go to the next &lt;STRONG&gt;id &lt;/STRONG&gt;value that is (2). if it has a respective observation in &lt;STRONG&gt;col3&lt;/STRONG&gt; then &lt;STRONG&gt;new_var&lt;/STRONG&gt; = c.&lt;/P&gt;&lt;P&gt;3) say &lt;STRONG&gt;id&lt;/STRONG&gt;= 1 and &lt;STRONG&gt;id&lt;/STRONG&gt; =2 's corresponding &lt;STRONG&gt;col3&lt;/STRONG&gt; values are blank, then and then only go to &lt;STRONG&gt;id&lt;/STRONG&gt;=3....and so on&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;how will I do this for the above dataset...If I were to sort I would sort by the dataset by&amp;nbsp;&lt;STRONG&gt;id.&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you please help me with the logic to do that? I hope this clears all the confusion.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Note&lt;/STRONG&gt;: This is a small part of the entire program and the &lt;STRONG&gt;id&amp;nbsp;&lt;/STRONG&gt;is dynamic for a dataset. I will have many such datasets like above with different &lt;STRONG&gt;id&lt;/STRONG&gt; values( meaning &lt;STRONG&gt;ds-1&lt;/STRONG&gt; will have &lt;STRONG&gt;id&lt;/STRONG&gt;'s 1,2...&lt;STRONG&gt;DS-2&lt;/STRONG&gt; will have &lt;STRONG&gt;id&lt;/STRONG&gt;s 1,2,3,&amp;nbsp; &amp;nbsp;&lt;STRONG&gt;ds-3&lt;/STRONG&gt; will have &lt;STRONG&gt;id&lt;/STRONG&gt;s 1 etc..). but the logic is the same for all the datasets...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Mar 2020 01:04:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creation-of-new-column-values-with-respect-to-multiple-column/m-p/635172#M21284</guid>
      <dc:creator>Saser_123</dc:creator>
      <dc:date>2020-03-27T01:04:57Z</dc:date>
    </item>
    <item>
      <title>Re: Creation of new column values with respect to multiple column values.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creation-of-new-column-values-with-respect-to-multiple-column/m-p/635175#M21286</link>
      <description>&lt;P&gt;Something like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=step1 ;
  by id;
run;

data want ;
  set step1;
  length new_var $8 ;
  new_var= coalescec(new_var,col3);
  retain new_var;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;Obs    name    col2     col3    id    new_var

 1      Y      Y,H,J     Y       1       Y
 2      C      Y,C,Z     C       2       Y
 3      Z      H,K,R             3       Y&lt;/PRE&gt;</description>
      <pubDate>Fri, 27 Mar 2020 01:53:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creation-of-new-column-values-with-respect-to-multiple-column/m-p/635175#M21286</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-03-27T01:53:13Z</dc:date>
    </item>
    <item>
      <title>Re: Creation of new column values with respect to multiple column values.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Creation-of-new-column-values-with-respect-to-multiple-column/m-p/635267#M21288</link>
      <description>&lt;P&gt;Thank you Tom for the code. Yes it works! I have not used coalescec() , thank you for introducing it to me. Since it is sorted by id and taking the first non empty value for new_var is a smart thought!&amp;nbsp;&lt;/P&gt;&lt;P&gt;Once again, Thank you for taking your time to help me out&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Mar 2020 10:51:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Creation-of-new-column-values-with-respect-to-multiple-column/m-p/635267#M21288</guid>
      <dc:creator>Saser_123</dc:creator>
      <dc:date>2020-03-27T10:51:15Z</dc:date>
    </item>
  </channel>
</rss>

