BookmarkSubscribeRSS Feed
jacksonan123
Lapis Lazuli | Level 10
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

110130000112300
110230000112300
11030212300
11040212300
11050212300
11060212300
11070212300
11080212300
11090212300
110100212300
110.486411020230.48640.02432
110120212300
1101330000112300
1101430000112300
110150212300
110160212300
110170212300
110180212300
110190212300
110200212300
110210212300
110220212300
110230212300
110240212300
4 REPLIES 4
novinosrin
Tourmaline | Level 20

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;
jacksonan123
Lapis Lazuli | Level 10
I changed the code to include the value for d2 but it didn't work. I still
got a dv=0 for cmt=23 though the value for d2 was in the d2 column.

data final;

set newl6;

d1=0.95*dv;

d2=0.05*dv;

if cmt=11 then dv=d1;

else if cmt=23 then dv=d2;


ballardw
Super User

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;
jacksonan123
Lapis Lazuli | Level 10
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.

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!

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