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

SAS Innovate 2025: Call for Content

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 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 990 views
  • 0 likes
  • 2 in conversation