data final; set newl6; d1=0.95*dv; if cmt=11 then dv=d1; run; data final1; set final; d2=0.05*dv; if cmt=23 then dv=d2; run;
I ran the attached code on this data set but the data set final1 code did not populate cmt=23. Can someone tell me why since it worked on CMT=11? Is there a better way to populate the desired CMTS 11 and 23 with the d1 and d2 values?
subj time dv cmt amt evid mdv wt d1 d2
1 | 1 | 0 | 1 | 30000 | 1 | 1 | 23 | 0 | 0 |
1 | 1 | 0 | 2 | 30000 | 1 | 1 | 23 | 0 | 0 |
1 | 1 | 0 | 3 | 0 | 2 | 1 | 23 | 0 | 0 |
1 | 1 | 0 | 4 | 0 | 2 | 1 | 23 | 0 | 0 |
1 | 1 | 0 | 5 | 0 | 2 | 1 | 23 | 0 | 0 |
1 | 1 | 0 | 6 | 0 | 2 | 1 | 23 | 0 | 0 |
1 | 1 | 0 | 7 | 0 | 2 | 1 | 23 | 0 | 0 |
1 | 1 | 0 | 8 | 0 | 2 | 1 | 23 | 0 | 0 |
1 | 1 | 0 | 9 | 0 | 2 | 1 | 23 | 0 | 0 |
1 | 1 | 0 | 10 | 0 | 2 | 1 | 23 | 0 | 0 |
1 | 1 | 0.4864 | 11 | 0 | 2 | 0 | 23 | 0.4864 | 0.02432 |
1 | 1 | 0 | 12 | 0 | 2 | 1 | 23 | 0 | 0 |
1 | 1 | 0 | 13 | 30000 | 1 | 1 | 23 | 0 | 0 |
1 | 1 | 0 | 14 | 30000 | 1 | 1 | 23 | 0 | 0 |
1 | 1 | 0 | 15 | 0 | 2 | 1 | 23 | 0 | 0 |
1 | 1 | 0 | 16 | 0 | 2 | 1 | 23 | 0 | 0 |
1 | 1 | 0 | 17 | 0 | 2 | 1 | 23 | 0 | 0 |
1 | 1 | 0 | 18 | 0 | 2 | 1 | 23 | 0 | 0 |
1 | 1 | 0 | 19 | 0 | 2 | 1 | 23 | 0 | 0 |
1 | 1 | 0 | 20 | 0 | 2 | 1 | 23 | 0 | 0 |
1 | 1 | 0 | 21 | 0 | 2 | 1 | 23 | 0 | 0 |
1 | 1 | 0 | 22 | 0 | 2 | 1 | 23 | 0 | 0 |
1 | 1 | 0 | 23 | 0 | 2 | 1 | 23 | 0 | 0 |
1 | 1 | 0 | 24 | 0 | 2 | 1 | 23 | 0 | 0 |
combine the 2 datsteps
data final; set newl6; d1=0.95*dv; if cmt=11 then dv=d1; run; data final1; set final; d2=0.05*dv; if cmt=23 then dv=d2; run;
to
data final; set newl6; d1=0.95*dv;
d2=.05*dv; if cmt=11 then dv=d1;
else if cmt=23 then dv=d2; run;
Since your variables do not align with the "data" it is very hard to read.
You should show the values before any calculation. Since your are overwriting the value of dv we can't see what the actual starting. But if the original value of dv was 0 where cmt=23 then d2 = 0* 0.05 = 0, so dv=d2 would = 0. A further clue that dv was 0 is that d1 =0 for cmt=23 also. So the final value of dv =0 is not a failed assignment.
If you expected a different value then show a starting value for dv not = 0 and the result. Some example code. Also see how to show data as a data step so we can test something.
data work.newl6; input subj time dv cmt amt evid mdv wt; datalines; 1 1 0.4864 11 0 2 0 23 1 1 .5 23 0 2 1 23 data work.final; set work.newl6; d1=0.95*dv; if cmt=11 then dv=d1; run; data work.final1; set work.final; d2=0.05*dv; if cmt=23 then dv=d2; run;
dATA NORMA;
SET NORM2A;
IF TIME=1 AND Y GT 11 THEN DELETE;
IF TIME=2 AND Y GT 28 THEN DELETE;
IF TIME=3 AND Y GT 27 THEN DELETE;
IF TIME=4 AND Y GT 26 THEN DELETE;
IF TIME=5 AND Y GT 15 THEN DELETE;
IF TIME=6 AND Y GT 15 THEN DELETE;
IF TIME=8 AND Y GT 15 THEN DELETE;
IF TIME=24 AND Y GT 15 THEN DELETE;
rename id=wsubj;
RUN;
proc print data=norma; run;
proc sort data=norma;
by wsubj time ;run;
data newL2;
do time=0 to 24 by 1;
DO CMT=1 TO 24;
do wsubj= 1 to 14;
OUTPUT;
END;
end;
end;
RUN;
proc sort data=newl2;
by wsubj time ;run;
data newl3;
retain wsubj time cmt;
set newl2;
if time=7 then delete;
if time=9 then delete;
if time=11 then delete;
if time=13 then delete;
if time=14 then delete;
if time=15 then delete;
if time=16 then delete;
if time=17 then delete;
if time=18 then delete;
if time=19 then delete;
if time=20 then delete;
if time=21 then delete;
if time=22 then delete;
if time=23 then delete;
keep wsubj time cmt;
run;
proc sort data=newl3;
by wsubj time ;run;
Data newl4;
merge norma newl3;
by wsubj time ;
y1=0.95*y;
y2=0.05*y;
run;
I was able to get the desired result by restructuring the SAS code to that which I posted above. The desired data was obtained by merging norma and newl3 and taking the desired fractions of y.
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.
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.