BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Raj00007
Calcite | Level 5

hi, i have a data  in Celsius, it need to convert into Fahrenheit, please help me in executing this code

whats wrong with this code?


data want;
set have;
array celsius(9)TmpNeg10 TempNeg5 Temp0 Temp5 Temp10 Temp15 Temp20 Temp25 Temp30;
array fahrenheit(9);
do i = 1 to 9;
fahrenheit(i) = ((9/5)*(i) + 32);
end;
run;
proc  print;
run;

 

Obs TmpNeg10 TempNeg5 Temp0 Temp5 Temp10 Temp15 Temp20 Temp25 Temp30 
1 -20 -14 -10 -2 3 8 12 17 26 
2 -26 -20 -15 -7 -2 4 8 13 22 
3 -30 -24 -18 -10 -5 1 5 11 20 
4 -33 -27 -21 -12 -7 -1 3 9 18 
5 -35 -29 -23 -14 -9 -3 2 7 17 
6 -37 -31 -25 -16 -10 -4 0 6 16 
7 -39 -32 -26 -18 -12 -6 -1 5 15 
8 -40 -34 -28 -19 -13 -7 -2 4 14 
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Kind of forgot the Celsius component:

data want;
set have;
array celsius(9)TmpNeg10 TempNeg5 Temp0 Temp5 Temp10 Temp15 Temp20 Temp25 Temp30;
array fahrenheit(9);
do i = 1 to 9;
fahrenheit(i) = ((9/5)*Celsius(i) + 32);
end;
run;
proc  print;
run;

View solution in original post

4 REPLIES 4
ballardw
Super User

Kind of forgot the Celsius component:

data want;
set have;
array celsius(9)TmpNeg10 TempNeg5 Temp0 Temp5 Temp10 Temp15 Temp20 Temp25 Temp30;
array fahrenheit(9);
do i = 1 to 9;
fahrenheit(i) = ((9/5)*Celsius(i) + 32);
end;
run;
proc  print;
run;
Raj00007
Calcite | Level 5
how could i even miss this. Anyways thank you
ballardw
Super User

@Raj00007 wrote:
how could i even miss this. Anyways thank you

Arrays will allow use of other brackets than () for the index.

For ancient reasons I use [ ] for array indexes such as Celsius[i] . That way when I am using an index value I remind myself to use the array name as well.

 

I have found this somewhat helpful in long equations with multiple nested parentheses to help keep the levels straight as well.

ChrisNZ
Tourmaline | Level 20

> whats wrong with this code?

The formatting of the code is non-existent. Help yourself and format your code.

 

There is also a typo in the question. Since forums are about communication, you might as well try to communicate as well as possible. It's hard enough understanding the question at times, without having to compound this difficulty with poor or lazy writing.

 

SAS Innovate 2025: Register Now

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!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 722 views
  • 0 likes
  • 3 in conversation