DATA Step, Macro, Functions and more

sas macros or base sas

Frequent Contributor
Posts: 77

sas macros or base sas

Dear all,


I am facing lot of trouble currently with the below situation that I am in. Request your help/ideas in solving this:


I have recently finished a project for which the requirement was:


There were so many raw sources for a report (soo many, trust me). I need to import them all in sas, do the calc and then export them into excel using ODS into the exact same format as the existing manual excel report they have been currently using. The current manual report consists of YTD data, Jan till date, they add numbers everymonth.


But my SAS report consists of only one month data as we did it as a testing phase and was almost successful.

Now, the challenge is that I need to do the same for all the other months and bring out the actual complete report. but my code is written to accommodate only one month data at a time. the imnport part I have done in EG without hardcoding, so if I need to import another month I have to change the month name and  data set names in the code and run the entire process flow. Also I need to include the appned queries and append the data sets to the first created dataset each time I import a new month data.


I find this really complex because, even if I manage to do this for now, when I handover this code, the others should be able to handle and mantain it.


Request you to kindly suggest some good ideas to deal with the sitiation..


Many Thanks..


Super User
Posts: 9,873

Re: sas macros or base sas

If you have already arrived at a stage where you only have to set a macro variable once and the code works on its own, then you just need to wrap your code into a macro that has the month macro variable as a parameter.

After that, you can call the macro repeatedly with call execute() off a dataset of months.

Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Posts: 23,237

Re: sas macros or base sas

You need to redesign your process so your data import and reporting are separated. So you first import and append your data in one step or process flow and then use a second to create the reports. This way the second, just uses the output from the first step of importing. 


Given what you've said it's harder to provide any further advice because it's a relatively vague question. But in general if you know you're going to have to automate a process it should be designed with some of those considerations in mind but that comes with time as well. 

Ask a Question
Discussion stats
  • 2 replies
  • 3 in conversation