DATA Step, Macro, Functions and more

DATA STEP

Reply
Super Contributor
Posts: 1,040

DATA STEP

IS THE "COMMENTED" AND THE "NON SCOMMENTED" LINES DOING THE SAME THING IN THE BELOW CODE????

THANKS

 

data want;

 

set ints_exts2;

 array ins int:;

 array outs ext:;

 do i = 1 to dim(ins);

 if ins(i)^=. and outs(i)^=. then duration=sum(duration,outs(i)-ins(i)) /*UNCOMMENTED*/

 *if 2=N(ins(i),outs(i)) then duration=sum(duration,outs(i)-ins(i));    /*COMMENTED*/

end

 ;

days = datepart(duration);

time = timepart(duration);

hrs=time/(60*60);

Total_vent_hours =days*24+ time/(60*60);

vent_days=Total_vent_hours/24;

 run;

Super User
Posts: 10,483

Re: DATA STEP

Not exactly as the Not missing, ^=., works for character variables while N(variables) requires all of the arguments to be numeric.

 

If you are dealing with mixed data types you might want CMISS(ins[i], out[i]) = 0

Super User
Posts: 17,784

Re: DATA STEP

If you have any other special missing values that also won't give you the same results.

data have;
a=.; b=2; output;
a=1; b=.N; output;
a=2; b=3; output;
a=.; b=.; output;
a=.A; b=.A; output;
run;

data want;
set have;
if a ne . and b ne . then flag=1;
else flag=0;
x=n(a,b);
run;
Super Contributor
Posts: 1,040

Re: DATA STEP

Thanks Reeza.

 

INS and OUTS arrays contain dates only. Can have missing values.

Wanted toi know if in that case both line output the same results??

 

Thanks

Super User
Posts: 10,483

Re: DATA STEP

You could check with:

compare =(ins(i)^=. and outs(i)^=.) = (N(ins(i),outs(i)));

Super User
Posts: 17,784

Re: DATA STEP

If you have a very specific scenario, it's faster to test it than ask. In general, no it won't, for your case it may, as long as you can guarantee that it will always stay that way.
Ask a Question
Discussion stats
  • 5 replies
  • 198 views
  • 0 likes
  • 3 in conversation