Hi,
I have a dataset with two sets of month variables. Each set has months going from 10 months before a target date to 10 months after.
ID Target_date mth_10_pre_a mth_9_pre_a mth_8_pre_a...mth_8_post_a mth_9_post_a mth_10_post_a mth_10_pre_b...etc.
1 2/2012 3 7 . 0 3 . .
What I want is to use values from the first set of month variables (a) to change some of the values in the second set of month variables from missing to 0; eg, since mth_10_pre_a has a value (or a 0), then mth_10_pre_b should be changed from missing to 0 (if mth_10_pre_b already had a positive value, however, it should remain unchanged).
I know that an array is theoretically the easiest way to do this, but since the numbers come in the middle of my variables, I'm not sure what's the most efficient way to go about it (ie, if there's a way to avoid changing all my variable names by hand).
Any help is much appreciated.
You don't give us the whole list of variables but I think what you want is an array solution. No need to change any variable names just list in order. Note that with the first list in place you can copy-paste- search and replace _a with _b so not terrible. So you likely have 21 variables (and I would guess at some time in the future more)
Data want;
set have;
array prea mth_10_pre_a mth_9_pre_a mth_8_pre_a ; /* continue to list all of the first group of variables just paste the names from any handy source*/
array preb mth_10_pre_b mth_9_pre_b mth_8_pre_b ; /* again continue matching the order of the previous line*/
do j= 1 to dim(prea);
if prea
end;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: