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

Hello,

 

I don't understand why my first program works and the second no (only changing the looping).

I need to add the currently month in the loop if anyone have ideas thanks a lot.

 

%let runasofdate= 20140101;
data creation;
rundate = input(put(&runasofdate,8.),yymmdd8.);
array psc0010_begin_date(*) psc0010_begin_date0-psc0010_begin_date11;
array psc0010_end_date(*) psc0010_end_date0-psc0010_end_date11;
do i =1 to 11  ;
psc0010_begin_date(i) = intnx('month',rundate,i,'begin');
psc0010_end_date(i)= intnx ('month', rundate, i , 'end');
 
end;
run;
 
And the second program doesn't working ..
 

 

%let runasofdate= 20140101;
data creation;
rundate = input(put(&runasofdate,8.),yymmdd8.);
array psc0010_begin_date(*) psc0010_begin_date0-psc0010_begin_date11;
array psc0010_end_date(*) psc0010_end_date0-psc0010_end_date11;
do i =0 to 11  ;
psc0010_begin_date(i) = intnx('month',rundate,i,'begin');
psc0010_end_date(i)= intnx ('month', rundate, i , 'end');
 
end;
run;
 
Thanks
1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

When the ARRAY statement contains this:

 

(*)

 

SAS counts the first element of the array as the one with subscript=1.  I you want i=0 to refer to the first element of the array, you have to change to using:

 

(0:11)

 

Otherwise, there is no element that corresponds to i=0.

View solution in original post

3 REPLIES 3
Astounding
PROC Star

When the ARRAY statement contains this:

 

(*)

 

SAS counts the first element of the array as the one with subscript=1.  I you want i=0 to refer to the first element of the array, you have to change to using:

 

(0:11)

 

Otherwise, there is no element that corresponds to i=0.

alexandralorenzo
Fluorite | Level 6
I found the solution an array cannot take a 0 value so I had to defined the array elements as you said.
But also change the loop.
Thanks for your answer
Ron_MacroMaven
Lapis Lazuli | Level 10
for macro users who want to generate a series of date values, see my paper
Macro Loops with Dates

http://www.sascommunity.org/wiki/Macro_Loops_with_Dates

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 3 replies
  • 1095 views
  • 0 likes
  • 3 in conversation