I am trying to create a sas job that assigns a week number to a group of 7 dates. So for example, March 1 - March 7 is Week 1, March 8 through March 15, is Week 2...etc.
I'd originally thought an 2-dim array would resolve this problem, but have given up on that idea.
The other option was to designate a system date value as Start date and increment Start date by a certain number. If the variable ddate is between the min and max start dates then a week number would assigned. Example here:
&start=17112; /* Denotes sys date value of 11/7/06 */
&end = 17139; /* Denotes sys date value of 12/4/06 */
data test;
input @1 ddate PD5.0; /*variable ddate is yyddmm. format*/
week=0;
start=&start;
if start <= ddate <= (start +6) then week=1;
if (start+7) <= date <= (start+13) then week=2;
IF (START+14) <= DDATE<= (START+20) THEN WEEK=3;
IF (START+21) <= DDATE<= (START+27) THEN WEEK=4;
IF (START+28) <= DDATE<= (START+30) AND DDATE<=END THEN WEEK=5;
END;
format ddate yymmdd10.;
run;
The problem that occurs is that SAS does not seem to be able to recognize DDate as having a system date value that falls between start point 1 and start point 2. Therefore, when I run a proc freq; tables week;, I get no returned values. The data infile has ddates that are between the start and end dates.
Note: This program is set up in a mainframe environment (I am not using PC SAS).
I'd originally thought an 2-dim array would resolve this problem, but have given up on that idea.
The other option was to designate a system date value as Start date and increment Start date by a certain number. If the variable ddate is between the min and max start dates then a week number would assigned. Example here:
&start=17112; /* Denotes sys date value of 11/7/06 */
&end = 17139; /* Denotes sys date value of 12/4/06 */
data test;
input @1 ddate PD5.0; /*variable ddate is yyddmm. format*/
week=0;
start=&start;
if start <= ddate <= (start +6) then week=1;
if (start+7) <= date <= (start+13) then week=2;
IF (START+14) <= DDATE<= (START+20) THEN WEEK=3;
IF (START+21) <= DDATE<= (START+27) THEN WEEK=4;
IF (START+28) <= DDATE<= (START+30) AND DDATE<=END THEN WEEK=5;
END;
format ddate yymmdd10.;
run;
The problem that occurs is that SAS does not seem to be able to recognize DDate as having a system date value that falls between start point 1 and start point 2. Therefore, when I run a proc freq; tables week;, I get no returned values. The data infile has ddates that are between the start and end dates.
Note: This program is set up in a mainframe environment (I am not using PC SAS).