BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
maysha2854
Calcite | Level 5

Suppose I have 2 dates column. If I take difference of date I get months, the difference of two dates is 2months. 

I want to update column Month1-Month11 as 1 and 0 for other columns(Month12-Month24=0).

I tried using array but it updated only column Month11 as 1. I want to update all columns before Month12(Month1-Month11)

 

Thank you in advance.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
data want;
    set have;
    array m m1-m12;
    do i=1 to dim(m);
        if i<diff then m(i)=1;
        else m(i)=0;
    end;
run;
--
Paige Miller

View solution in original post

6 REPLIES 6
maysha2854
Calcite | Level 5
Suppose I have 2 dates column. If I take difference of date I get months, the difference of two dates is 12months.

I want to update column Month1-Month11 as 1 and 0 for other columns(Month12-Month24=0).

I tried using array but it updated only column Month11 as 1. I want to update all columns before Month12(Month1-Month11)



Thank you in advance.
PaigeMiller
Diamond | Level 26

Please explain in more detail. Show us a small example. Show us the desired output from the small example. Show us the code you tried that didn't work.

--
Paige Miller
maysha2854
Calcite | Level 5
Date1 Date2 Diff M1 M2 M3 M4 M5 M6 M7 M8 M9 M10 M11 M12
Dec-19 Aug-20 8 . . . . . . . . . . . .
Sep-19 Mar-20 6 . . . . . . . . . . . .



Output

Date1 Date2 Diff M1 M2 M3 M4 M5 M6 M7 M8 M9 M10 M11 M12
Dec-19 Aug-20 8 1 1 1 1 1 1 1 0 0 0 0 0
Sep-19 Mar-20 6 1 1 1 1 1 0 0 0 0 0 0 0



My Approach

data want
set have
array a1(8) month1-Month7
array a2(6) Month1-Month5
if Date_Diff =8 then a1(8) =1;
if Date_Diff =6 then a2(6) =1;
run;


maysha2854
Calcite | Level 5
My Approach

data want
set have
array a1(7) month1-Month7
array a2(5) Month1-Month5
if Date_Diff =8 then a1(7) =1;
if Date_Diff =6 then a2(5) =1;
run;
PaigeMiller
Diamond | Level 26
data want;
    set have;
    array m m1-m12;
    do i=1 to dim(m);
        if i<diff then m(i)=1;
        else m(i)=0;
    end;
run;
--
Paige Miller

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 6 replies
  • 1639 views
  • 0 likes
  • 2 in conversation