Help using Base SAS procedures

Repeating Values

Reply
Occasional Contributor
Posts: 14

Repeating Values

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. 

 

Super User
Posts: 23,724

Re: Repeating Values

Posted in reply to SuperSaiyan

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. 

 


 

Occasional Contributor
Posts: 14

Re: Repeating Values

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. 

Occasional Contributor
Posts: 14

Re: Repeating Values

Posted in reply to SuperSaiyan
also, tried doing the do loop, but I cannot fully get it.
Occasional Contributor
Posts: 14

Re: Repeating Values

Posted in reply to SuperSaiyan
how do I repeat the two values?
Super User
Posts: 23,724

Re: Repeating Values

Posted in reply to SuperSaiyan
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;
Super User
Posts: 23,724

Re: Repeating Values

Posted in reply to SuperSaiyan
You need to show your code.
Occasional Contributor
Posts: 14

Re: Repeating Values

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

Super User
Super User
Posts: 9,599

Re: Repeating Values

Posted in reply to SuperSaiyan

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.  

Occasional Contributor
Posts: 14

Re: Repeating Values

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

Super User
Super User
Posts: 9,599

Re: Repeating Values

Posted in reply to SuperSaiyan

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;
Occasional Contributor
Posts: 14

Re: Repeating Values

Posted in reply to SuperSaiyan

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

Super User
Super User
Posts: 9,599

Re: Repeating Values

Posted in reply to SuperSaiyan

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;
Occasional Contributor
Posts: 14

Re: Repeating Values

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.
Ask a Question
Discussion stats
  • 13 replies
  • 365 views
  • 0 likes
  • 3 in conversation