DATA Step, Macro, Functions and more

macro

Accepted Solution Solved
Reply
Contributor
Posts: 65
Accepted Solution

macro

I run the data and got the results as following:

 

Original 2015 Average Allowed Amount

Projected 2017 Allowed Amount

Projected Percent Change

$22,768.81

$22,762.06

-0.03%

We have new data next year and I want to run the new data, but the years have to be updated into "2016" and "2018" respectively. The "

Original 2015 Average Allowed Amount" and "Projected 2017 Allowed Amount" are variable names in my data. I don't want to manually change the variable names each year. I tried to define macro variable names to update the years automatically, but I failed. Any ideas, suggestions and recommendations will be greatly appreciated!


Accepted Solutions
Solution
‎01-30-2017 04:19 PM
Contributor
Posts: 66

Re: macro

[ Edited ]
Posted in reply to zhuxiaoyan1

Hi, you have a few options depending on what you want. You could say:

%let year=2018;

%let prev=%eval(&year-2);

title "Original &prev Average Allowed Amount" and "Projected &year Allowed Amount";

 

Then just change the first statement as needed.

 

Or if you know it is one year in the future and one year in the past.

%let next=%eval(%substr(&sysdate9, 6, 4)+1);

%let prev=%eval(&next-2);

title "Original &prev Average Allowed Amount" and "Projected &next Allowed Amount";

 

Michelle

View solution in original post


All Replies
Solution
‎01-30-2017 04:19 PM
Contributor
Posts: 66

Re: macro

[ Edited ]
Posted in reply to zhuxiaoyan1

Hi, you have a few options depending on what you want. You could say:

%let year=2018;

%let prev=%eval(&year-2);

title "Original &prev Average Allowed Amount" and "Projected &year Allowed Amount";

 

Then just change the first statement as needed.

 

Or if you know it is one year in the future and one year in the past.

%let next=%eval(%substr(&sysdate9, 6, 4)+1);

%let prev=%eval(&next-2);

title "Original &prev Average Allowed Amount" and "Projected &next Allowed Amount";

 

Michelle
Contributor
Posts: 65

Re: macro

Posted in reply to mbuchecker

Thank you!

PROC Star
Posts: 7,492

Re: macro

Posted in reply to zhuxiaoyan1

It would help if you showed the code you tried and indicated what you're actual variable names are. Do they "really" have spaces in them, or are those just the variable labels?

 

Art, CEO, AnalystFinder.com

 

Super User
Posts: 11,343

Re: macro

Posted in reply to zhuxiaoyan1

You may need to show your existing code to make suggestions pointed to specific items of your existing code.

 

Since "Original 2015 Average Allowed Amount" is definitely not a normal SAS variable name details could be critical to getting working code.

Contributor
Posts: 65

Re: macro

Yes, you are right. They are labels, not variable names. Sorry about this confusion. I used mbuchecker's code and added label statement and got it fixed. Thank you for your input!

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 175 views
  • 0 likes
  • 4 in conversation