计算中使用的提示或宏变量 [英] Prompt or Macro Variables used in calculations

查看:32
本文介绍了计算中使用的提示或宏变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 EG 中的提示管理器创建了一个数值变量.

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

这个变量被称为 HYr,代表我提取的数据最高的年份.

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

运行程序时,我根据最高年份创建了 4 个新变量,这就是我遇到问题的地方.

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

我有以下几点:

%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.

我知道这可能只是一个简单的语法问题,如果有足够的时间我可能能够解决它,但我办公室里没有人比我拥有更好的 SAS 技能,而且这并不多.

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.

提前致谢.

推荐答案

使用 %EVAL() 对整数和宏变量进行计算.

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.;

如果您尝试进行其他包含小数的计算,则需要改用 %SYSEVALF.

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.;

这篇关于计算中使用的提示或宏变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆