BookmarkSubscribeRSS Feed
sahoositaram555
Pyrite | Level 9

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.

2 REPLIES 2
Kurt_Bremser
Super User

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).

 

mkeintz
PROC Star

@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?

 

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1298 views
  • 0 likes
  • 3 in conversation