Aphreven Tracker
https://communities.sas.com/kntur85557/tracker
Aphreven TrackerSat, 18 May 2024 07:49:52 GMT2024-05-18T07:49:52Zshifted groupby
https://communities.sas.com/t5/New-SAS-User/shifted-groupby/m-p/907671#M40597
<P>I would like from a table with 2 columns Group and Value, to create a new column shift_n_value<BR />This column should be the column Value but N shifted by group.</P><P> </P><P>For example if shift by one, the output should be : </P><TABLE border="1"><TBODY><TR><TD>Group</TD><TD>Value</TD><TD>shift_n_value</TD></TR><TR><TD>A</TD><TD>2</TD><TD>.</TD></TR><TR><TD>A</TD><TD>1</TD><TD>2</TD></TR><TR><TD>A</TD><TD>3</TD><TD>1</TD></TR><TR><TD>A</TD><TD>1</TD><TD>3</TD></TR><TR><TD>B</TD><TD>4</TD><TD>.</TD></TR><TR><TD>B</TD><TD>2</TD><TD>4</TD></TR><TR><TD>B</TD><TD>0</TD><TD>2</TD></TR></TBODY></TABLE><P>If i shift twice:</P><P> </P><TABLE border="1"><TBODY><TR><TD>Group</TD><TD>Value</TD><TD>shift_n_value</TD></TR><TR><TD>A</TD><TD>2</TD><TD>.</TD></TR><TR><TD>A</TD><TD>1</TD><TD>.</TD></TR><TR><TD>A</TD><TD>3</TD><TD>2</TD></TR><TR><TD>A</TD><TD>1</TD><TD>1</TD></TR><TR><TD>B</TD><TD>4</TD><TD>.</TD></TR><TR><TD>B</TD><TD>2</TD><TD>.</TD></TR><TR><TD>B</TD><TD>0</TD><TD>4</TD></TR></TBODY></TABLE><P><BR />Basically it is the equivalent in python to : df['shift_n_value'] = df.groupby('group')['value'].shift(n)</P><P> </P>Tue, 12 Dec 2023 22:20:00 GMThttps://communities.sas.com/t5/New-SAS-User/shifted-groupby/m-p/907671#M40597Aphreven2023-12-12T22:20:00Zbackward fill and forward fill
https://communities.sas.com/t5/New-SAS-User/backward-fill-and-forward-fill/m-p/896960#M39908
<P>Hello I would like to do something very simple but that I struggle with : </P><P> </P><P>I have a table with several columns and 1 specifically that have missing values that i want to fill with a backward then a forward fill stragegy based on a ID column. </P><P> </P><P>have : </P><P>ID colA colB Coltofill </P><P>1 ... ... </P><P>1 </P><P>1 5 </P><P>2 12 </P><P>2 </P><P> </P><P>want : </P><P>ID colA colB Coltofill </P><P>1 ... ... 5 </P><P>1 5 </P><P>1 5 </P><P>2 12 </P><P>2 12</P><P> </P><P>More precisely i want to only fill the col "Coltofill". I found a good reponse in this post : <A href="https://communities.sas.com/t5/SAS-Programming/Backward-and-Forward-Filling-Information/m-p/699624" target="_self">https://communities.sas.com/t5/SAS-Programming/Backward-and-Forward-Filling-Information/m-p/699624</A> But the problem is that it fills every columns. </P><P> </P><P>Thank you !</P><P> </P>Tue, 03 Oct 2023 15:17:04 GMThttps://communities.sas.com/t5/New-SAS-User/backward-fill-and-forward-fill/m-p/896960#M39908Aphreven2023-10-03T15:17:04Z