Prompt or Macro Variables used in calculations

本秂侑毒 提交于 2019-12-02 00:34:30

问题


I have created a numeric variable using the Prompt Manager in EG.

This variable is called HYr for the highest year of data that I am pulling.

When running the program I create 4 new variables based on the highest year and this is where I am having issues.

I have the following:

%Let Yr2 = &HYr. - 1;

%Let Yr3 = "&HYr." - 2;

%Let Yr4 = &HYr. - 3;

%Let Yr5 = '&HYr.' - 4;

I am trying to subtract the value from the year and the new variable will be used in determining date ranges that are being pulled. I am trying several things and learning in the process but I am still stuck.

I know it is probably just a simple syntax issue and given enough time I will probably be able to get it but no one in my office has any better SAS skills than I do and that isn't much.

thanks in advance.


回答1:


Use %EVAL() to do calculations with integers and macro variables.

%let HYR = 2018;
%Let Yr2 = %eval(&HYr. - 1);
%Let Yr5 = %eval(&HYr. - 4);

%put HYR: &hyr;
%put YR2: &yr2.;
%put YR5: &yr5.;

EDIT: If you were trying to do other calculations that included decimals you would need to use %SYSEVALF instead.

%let HYR = 2018;
%Let Yr2 = %sysevalf(&HYr. - 0.1);
%Let Yr5 = %sysevalf(&HYr. - 0.4);

%put HYR: &hyr;
%put YR2: &yr2.;
%put YR5: &yr5.;


来源:https://stackoverflow.com/questions/50065034/prompt-or-macro-variables-used-in-calculations

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!