BookmarkSubscribeRSS Feed
NagendraBS
Fluorite | Level 6
Hi, I need to create a dataset for each month for each branch with all d transactions. So I need to create automatically increment the months up to 12 months in one macro . Please provide your suggestions. I tried creating do loop but not able to calculate character value in evaluating function. Thanks in advance. Waiting for your tips
3 REPLIES 3
Reeza
Super User

Use the INTNX function. It's not exactly clear what you want, but maybe this will help you get started.

 

%macro loop;

%do i=1 %to 12;

%let date=%sysfunc(intnx(month, %sysfunc(today()), &i.), date9.);

%put &date.;

%end;

%mend;

%loop;
Astounding
PROC Star

My best tip:  write a program with no macro language, that works for a single month.  Then we can worry about how to make it loop over a set of months.

ballardw
Super User

My first thing involving any time, date or datetime related issue: Make sure the values are SAS time, date or datetime valued variables.

 

You don't say what you are going to do with multiple datasets but I bet it compounds doing more looping, macro or otherwise. Formats for the date variables can create very useable groups. Here's a very simple example. The first data step is just to create some dummy data for the proc tabulate to demonstrate creating a report with separate sections for the branch and totals by month.

data example;
   length account $ 15;
   do branch = 'A','B','C';
      do num = 1001 to 1005;
         account= cats(branch,num);
         do date = '01jan2015'd to '15jul2015'd by 20;
            deposit = round(1000*ranuni(456),.01);
            output;
         end;
      end;
   end;
run;

proc tabulate data=example;
   class branch date;
   format date monyy7.;
   var deposit;
   tables branch,
          date='Month',
          Deposit*sum*f=dollar10.2
          ;
run;
         

You can get similar results from proc means, freq, summary and report using formats on a single date varible. Also most of the modeling procedures will honor the format for creating levels of modeled variables.

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 7361 views
  • 3 likes
  • 4 in conversation