Hello experts:
I would like to do the following steps.
I am wondering if the SAS could perform this procedure. Thanks ahead.
Then you can try the below code so as to reduce the number of the lines
data want;
set have;
array grp1(*) Dose1_Group1 Date1_Group1 Productor1_Group1 ;
array grp2(*) Dose2_Group2 Date2_Group2 Productor2_Group2 ;
array grp3(*) temp1 temp2 temp3 ;
do i = 1 to dim(grp1);
grp3(i)=grp1(i);
if error=1 then do;
grp1(i)=grp2(i);
grp2(i)=grp3(i);
end;
end;
if error=1 then do;
temp4=Manufacture1_Group1;
Manufacture1_Group1=Manufacture2_Group2;
Manufacture2_Group2=temp4;
end;
run;
data want;
set have;
if error=1 then do;
temp=dose1_group1;
dose1_group1=dose2_group2;
dose2_group2=temp;
/* Repeat the above for all other variables */
/* which could be done using ARRAYs if desired */
end;
drop temp;
run;
By the way, why make your variable names so complicated? Wouldn't dose1 and dose2 be sufficient, instead of dose1_group1 and dose2_group2?
If you consider that except error variable, all the other variables are character then you can use arrays as below
data want;
set have;
array grp1(*) $ Dose1_Group1 Date1_Group1 Productor1_Group1 Manufacture1_Group1;
array grp2(*) $ Dose2_Group2 Date2_Group2 Productor2_Group2 Manufacture2_Group2;
array grp3(*) $ temp1 temp2 temp3 temp4;
do i = 1 to dim(grp1);
grp3(i)=grp1(i);
if error=1 then do;
grp1(i)=grp2(i);
grp2(i)=grp3(i);
end;
end;
run;
I apologize I didn't specify the variables. Some variables like dose, date, and product are numeric, some variable like manufacture is character.
Then you can try the below code so as to reduce the number of the lines
data want;
set have;
array grp1(*) Dose1_Group1 Date1_Group1 Productor1_Group1 ;
array grp2(*) Dose2_Group2 Date2_Group2 Productor2_Group2 ;
array grp3(*) temp1 temp2 temp3 ;
do i = 1 to dim(grp1);
grp3(i)=grp1(i);
if error=1 then do;
grp1(i)=grp2(i);
grp2(i)=grp3(i);
end;
end;
if error=1 then do;
temp4=Manufacture1_Group1;
Manufacture1_Group1=Manufacture2_Group2;
Manufacture2_Group2=temp4;
end;
run;
Hello, Jagadishkatam
Most of your codes are correct, except adding one "$" to the character switch. It's because I have multiple character variables.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.