BookmarkSubscribeRSS Feed
SuperSaiyan
Calcite | Level 5

Hello, any input would be appreciated, I'm trying to do the problem with a do loop statement but I cannot produce the expected output.

 

amount with levels 0.9, 0.8, 0.7 and 0.6, and concentration with levels 1%, 1.5%, 2%, 2.5% and 3%, to chemical reaction time.

The data contains: 10.9 11.5 9.8 12.7 10.6 9.2 10.3 9.0 10.6 9.4 8.7 9.7 8.2 9.4 8.5 7.2 8.6 7.5 9.7 7.7

Each row corresponds to the levels of amount and each column corresponds to the levels of concetration.

Create a permanent SAS data set with this format: concentration amount time

1% 0.9 10.9

1.5% 0.9 11.5

. . .

2.5% 0.6 9.7

3% 0.6 7.7

Thanks. 

 

13 REPLIES 13
Reeza
Super User

Please post what you’ve tried so far. It’s easier to help point out where things need to be fixed. 

Your question is also a bit unclear though so think you’re trying to create a SAS data set out of the values below the table? And a second table of all possible combinations, ergo the do loop?

 


@SuperSaiyan wrote:

Hello, any input would be appreciated, I'm trying to do the problem with a do loop statement but I cannot produce the expected output.

 

amount with levels 0.9, 0.8, 0.7 and 0.6, and concentration with levels 1%, 1.5%, 2%, 2.5% and 3%, to chemical reaction time.

The data contains: 10.9 11.5 9.8 12.7 10.6 9.2 10.3 9.0 10.6 9.4 8.7 9.7 8.2 9.4 8.5 7.2 8.6 7.5 9.7 7.7

Each row corresponds to the levels of amount and each column corresponds to the levels of concetration.

Create a permanent SAS data set with this format: concentration amount time

1% 0.9 10.9

1.5% 0.9 11.5

. . .

2.5% 0.6 9.7

3% 0.6 7.7

Thanks. 

 


 

SuperSaiyan
Calcite | Level 5

The question was also bit unclear to me, but I think my teacher wants to produce repeated values for the concentration levels and amount levels per reaction time. First I tried merging, but as expected it only merged the data. 

SuperSaiyan
Calcite | Level 5
also, tried doing the do loop, but I cannot fully get it.
SuperSaiyan
Calcite | Level 5
how do I repeat the two values?
Reeza
Super User
I think you two nested do loops.
A basic example is here

Data temp;
Do concrete=1,3,5;
Do iron = 2,3,6;
Output;
End;
End;
Run;
Reeza
Super User
You need to show your code.
SuperSaiyan
Calcite | Level 5

data chemical;

do amount =0.9,0.8,0.7,0.6;

do concentration=1%,1.5%,2%,2.5%,3%;

input amount concentration time;

output;

end;

end;

datalines;

10.9 11.5 9.8 12.7 10.6 9.2 10.3 9.0 10.6 9.4 8.7 9.7 8.2 9.4 8.5 7.2 8.6 7.5 9.7 7.7

;

run;

 

tried using the codes above but it shows error

RW9
Diamond | Level 26 RW9
Diamond | Level 26

This is not valid:

1%,1.5%,2%,2.5%,3%;

 

Use a number then apply a format.  Also use the {i} code window for code to retain formatting:

data chemical;
  do amount =0.9,0.8,0.7,0.6;  
    do concentration=1 to 3 by 0.5;
      output;
    end;
  end;
run;

As for why you have the datalines there at all is a mystery to me?  Explain what you want out.  

SuperSaiyan
Calcite | Level 5

Hello,

 

I tried another one using

 

data chemical;
do amount = .9 , .8 , .7 , .6 ;
do concentration= "1%" , "1.5%" , "2%" , "2.5%" , "3%" ;
input time@@;
output;
end;
end;
datalines;
10.9 11.5 9.8 12.7 10.6
9.2 10.3 9.0 10.6 9.4
8.7 9.7 8.2 9.4 8.5
7.2 8.6 7.5 9.7 7.7
;
run;

proc print data=chemical;
run;

 

but it cannot read the percentage with decimal point as expected,

 

it showssss.PNG

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Use the code window = {i}.  Something like:

data times;
  input time@@;
datalines;
10.9 11.5 9.8 12.7 10.6
9.2 10.3 9.0 10.6 9.4
8.7 9.7 8.2 9.4 8.5
7.2 8.6 7.5 9.7 7.7
;
run;

data want;
  set times;
  do amount=0.9 to 0.6 by -0.1;
    do concentration=1 to 3 by 0.5;
      output;
    end;
  end;
  format concentration percent 4.1;
run;
SuperSaiyan
Calcite | Level 5

SSSSS.PNG I tried running the codes you gave but the ouput is attache here, 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Typo, there was a space after the word percent which shouldn't be there:

data times;
  input time@@;
datalines;
10.9 11.5 9.8 12.7 10.6
9.2 10.3 9.0 10.6 9.4
8.7 9.7 8.2 9.4 8.5
7.2 8.6 7.5 9.7 7.7
;
run;

data want;
  set times;
  do amount=0.9 to 0.6 by -0.1;
    do concentration=1 to 3 by 0.5;
      output;
    end;
  end;
  format concentration percent4.1;
run;
SuperSaiyan
Calcite | Level 5
I have attached a photo of the supposed output, but I have problems with the percentages, i cannot it out the percentages with decimal points.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 13 replies
  • 2048 views
  • 0 likes
  • 3 in conversation