BookmarkSubscribeRSS Feed
robertrao
Quartz | Level 8

*Question1;

if i have 10 different observations(subjects) and I am creating an array in that dataset like

j=1

L=1

do i =1 to 30;

date(i)=

Suppose if the 30 of the newly created variables have dates like 05/01/2013 05/02/2013.............05/30/2013

Will these be retained for all the 10 subjects as well????

Can some one show me with an example???

Regards

5 REPLIES 5
robertrao
Quartz | Level 8

*Question2;

j=1

L=1

do i =1 to 30;

if variable x ne " " then do;

variable(j)=;                            /*j has lesser array length than i*/

j+1;

end;

run;

Why do the j=1 and L=1 have to be outside of the do loop??

if i put inside of the do loop only the last iteration is outputted!!!!

when do we have to use J+1 ?Could someone explain the logic please with an example preferably!!!!

Thanks

ArtC
Rhodochrosite | Level 12

In the first step that follows the 30 dates are created for each observation so retaining is not necessary.

data want;

   set sashelp.class;

   array dates {30} date1-date30;

   do date = '01may2013'd to '30may2013'd;

      output want;

   end;

   run;

In the second example the array is filled once and then the observations are read in a DOW loop.  This step could be simplified, but will be more efficient for large data sets.  In either case I am not sure that you really want the thirty dates repeated for each observation.

data want2;

   retain date1-date30 .;

   array dates {30} date1-date30;

   i=0;

   do date = '01may2013'd to '30may2013'd;

      i+1;

      dates{i}=date;

   end;

   do until(done);

      set sashelp.class end=done;

      output want2;

   end;

   stop;

   run;

robertrao
Quartz | Level 8

Sorry sir,

That was my mistake..

there was another step in between......which i added in the below code now....

According to my understanding the below creates dates1 to dates30 and if my macro variables

mo=JAN

yr=2011

dates(i)=mdy("01&mo.&yr."d),i,&yr);

is this part retaining the dates????

j=1

L=1

do i =1 to 30;

dates(i)=mdy("01&mo.&yr."d),i,&yr);

if variable x ne " " then do;

variable(j)=.........;                            /*j has lesser array length than i*/

j+1;

end;

run;

ArtC
Rhodochrosite | Level 12

Even so this is not a full DATA step.  there is no DATA or SET statement.The macro variables are defined elsewhere?

Retaining values is across observations.  Since we cannot see where the observations are coming from or what variables are on the PDV, we have to guess as to what is being retained.

Can you perhaps modify one of my silly examples from above using the CLASS data set to show us what you have so far and what you want to have happen?

ArtC
Rhodochrosite | Level 12

Array values are not retained unless you specify a retain statement or if you use a temporary array.  Since we can only see a fragment of your DATA step, it is not obvious how to answer your questions.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 1066 views
  • 3 likes
  • 2 in conversation