BookmarkSubscribeRSS Feed
CharlotteCain
Quartz | Level 8

Hey SAS Experts,

Please correct my understanding of the PDV in the below code:

The program runs perfectly fine.

data have;

input id $ date value holddate holdvalue lastdate lastvalue;

informat date holddate lastdate ddmmyy10.;

format date holddate lastdate ddmmyy10.;

datalines;

A 7/10/2014 11840 7/10/2014 11840 4/10/2014 15280

;

data need;

set have;

if date ne lastdate+1 then do date=lastdate+1 to holddate-1;

      value=lastvalue;

      output;

     end;

     putlog _all_; /* I tried looking at the PDV details, still haven't understood though */

     value=holdvalue;

  lastdate=date;

  lastvalue=value;

  output;

run;

Where does it say in the program after the conditional do loop to get the date value to 7/10/2014 as it outputs exactly what is needed?I.e My point is after the execution of the do loop, shouldn't date have the value of 6/10/2014 in the PDV? how did it correctly change to 7/10/2014 after i.e during the execution of 2nd output statement?

I know I am breaking my head for something simple, but your quick help would mean a lot to me.

Many thanks,

Charlotte

2 REPLIES 2
Ksharp
Super User

Very Interesting Question.

do date=lastdate+1 to holddate-1;    <=>   do date=lastdate+1 to holddate-1  by 1;

Maybe date will add one automatically  when it reach holddate-1 . therefore date actually would be holddate-1+1 = holddate .

Anyway it is good know this about SAS syntax.

Xia Keshan

data_null__
Jade | Level 19

I think this illustrates how it works more clearly than your example.  The index is incremented and then compared to stop leaving the value of I at 4 when the loop is finished.  You could use UNTIL to make it stop and leave the index eq to stop..

data _null_;
  
do i = 1 to 3;
     
put i=;
      end;
  
put i=;
   run;

i=
1
i=
2
i=
3
i=
4


data _null_;
  
do i = 1 to 3 until(i eq 3);
      put i=;
      end;
  
put i=;
   run;

i=
1
i=
2
i=
3
i=
3

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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