Hi experts,
I've YAS0 YES0 YCS0 YAS1 YES1 YCS1 YAS3 YES3 YCS3 columns where I have values such as "Atrisk" in all YAS columns, similarly "Events" for YES columns and "Censor" for all YCS columns and total I've about 9547 rows and only 1st rows of each column has the values. I would like to caryy forword the values to all 9657 rows.
Could anyone guide me though how to modify the below written code to achieve the results.
data plot_data_fin; merge plot_datafin transposed_gen_mod; by row;hw_lcl_lag=lag(hw_lcl); ARRAY cols {*} YAS: YES: YCS: ; Do i=1 to dim(cols); if COLS[i]=" " then COLS[i]=lag(COLS[i]); end; run;
I have tried to do it through do over loop but couldn't finish it till end.Let me know if i'm on track and help with a solution to modify the code to achieve the results.
You can't use LAG() like this to get your "carry forward", because you always feed the current value (missing) into the lag queue by calling the function before you set the variable.
You need to use a temporary array (which is automatically retained).
@sahoositaram555 wrote:
Hi experts,
I've YAS0 YES0 YCS0 YAS1 YES1 YCS1 YAS3 YES3 YCS3 columns where I have values such as "Atrisk" in all YAS columns, similarly "Events" for YES columns and "Censor" for all YCS columns and total I've about 9547 rows and only 1st rows of each column has the values. I would like to caryy forword the values to all 9657 rows.
Could anyone guide me though how to modify the below written code to achieve the results.
data plot_data_fin; merge plot_datafin transposed_gen_mod; by row;hw_lcl_lag=lag(hw_lcl); ARRAY cols {*} YAS: YES: YCS: ; Do i=1 to dim(cols); if COLS[i]=" " then COLS[i]=lag(COLS[i]); end; run;I have tried to do it through do over loop but couldn't finish it till end.Let me know if i'm on track and help with a solution to modify the code to achieve the results.
You have two datasets: plot_datafin and transposed_gen_mod. If you show sample data for both, we can provide useful responses than might not require looping, or even temporary (automatically retained) variables.
For instance, I don't understand what you mean by "1st rows of each column". If you mean the first row (i.e. first observation) of the 9,567 rows, then it would be easy to program retrieval of the variables you name once from obsrvation 1, with automatic retention, while processing all the other variables in the remaining 9,566 rows.
Do both of your datasets have 9,547 rows?
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.