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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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