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 open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.