如何在SAS中进行弧度和度数的切换

问题描述 投票:0回答:1

只是在寻找一种简单的方法来运行SAS中的三角函数,而不必在每次计算中手动修正。 以下是我正在使用的东西。

我可能是在SAS 9中运行的,SAS Studio学生模块,但这是一个一般的SAS问题。

我已经手动创建了一个变量,'rad'在'calc'数据步骤来处理这个问题,但它增加了一个步骤的复杂性,我想避免。

我想问的是,是否有一个系统设置、备用三角函数或...?bh_x = cos(rad*bh_a)*bh_l ;改为:bh_x = cos(bh_a)*bh_l ;这样我就不必为了三角函数的工作而手动将我的度数转换为弧度了。

感谢任何阅读此文的人,并为解决这个问题付出任何精神努力!蒂姆。

data spec   ;
    length
        b2h_a 8
        b2h_l 8
        b2h_l_e 8
        bike $ 8
        name $ 16
    ;
    input
        bike $
        name $
        bh_a
        bh_l
        ht_a
        spcr
        st_h
        st_a
        st_l
        hb_r
        hb_a
    ;
    datalines   ;
        srcn (0,0) 0 0 67 0 0 0 0 0 0
        srcn c 41 658 71.5 27 40 25 120 100 13
        srcn ne_27_n13 41 658 71.5 27 40 27 127 100 13
        srcn ne_15_0 41 658 71.5 15 40 27 127 100 0
        srcn ne_5_0 41 658 71.5 5 40 27 127 100 0 
        srcn ne_2_n9 41 658 71.5 2 40 27 127 100 9
        srcn ne_5_10 41 658 71.5 5 40 27 127 100 -10
        srcn ne_10_rf10 41 658 71.5 10 40 27 127 20 -10
        srcn max 41 658 90 250 0 0 250 0 0
    ;
run ;

data calc   ;
    set spec    ;

    pi=constant('pi')   ;
    rad=pi/180  ;

    bh_x = cos(rad*bh_a)*bh_l   ;
    bh_y = sin(rad*bh_a)*bh_l   ;

    sr_x = (cos(rad*ht_a)*(spcr+st_h/2))*-1 ;
    sr_y = sin(rad*ht_a)*(spcr+st_h/2);

    st_x = cos(rad*(90-ht_a+st_a))*st_l ;
    st_y = sin(rad*(90-ht_a+st_a))*st_l ;

    hb_x = cos(rad*(90-hb_a))*hb_r*-1   ;
    hb_y = sin(rad*(90-hb_a))*hb_r  ;

    hd_x = bh_x + sr_x + st_x + hb_x    ;
    hd_y = bh_y + sr_y + st_y + hb_y    ;

    if hd_x=0 then do   ;
        b2h_a=0 ;
        b2h_l=0 ;
    end ;
    else do ;
        b2h_a = atan(hd_y/hd_x)/rad ;
        b2h_l = hd_y/sin(b2h_a*rad) ;
    end ;

    b2h_l_e = b2h_l/25.4    ;

    drop pi rad ;

    format
        b2h_a 5.
        b2h_l 5.
        b2h_l_e 5.
        bh_a 5.
        bh_l 5.
        ht_a 5.
        spcr 5.
        st_h 5.
        st_a 5.
        st_l 5.
        hb_r 5.
        hb_a 5.
        bh_x 5.
        bh_y 5.
        sr_x 5.
        sr_y 5.
        st_x 5.
        st_y 5.
        hb_x 5.
        hb_y 5.
        hd_x 5.
        hd_y 5.
        b2h_a 5.
        b2h_l 5.
        b2h_l_e 5.1
        ;

run ;
math sas trigonometry degrees radians
1个回答
0
投票

SAS中没有接受DEGREE或GRADIAN参数的三角函数。 你总是需要从你的数据的角度测量系统转换到RADIAN。

您可以编写一个宏来执行转换。例子

%macro cosD(theta);
  %* theta is angle in degrees;
  %* emit data step source code that performs conversion from degrees to radians;
  cos(&theta*constant('PI')/180)
%mend;

使用中:

data calc   ;
    set spec    ;

    bh_x = %cosD(bh_a) * bh_l   ;

你可以在以下步骤中将角度数据转换为弧度数据 input 发生,然后不必再担心。

© www.soinside.com 2019 - 2024. All rights reserved.