DATA Step, Macro, Functions and more

Help with macro in SAS

Accepted Solution Solved
Reply
Occasional Learner
Posts: 1
Accepted Solution

Help with macro in SAS

 the idea is this, I need the macro to change my data and set as the days months and year.
i have 44 dataset are called like this:
 
Acr_maestro_mes_ant_20150131
Acr_maestro_mes_ant_20150331
Acr_maestro_mes_ant_20150430
.....................................................
Acr_maestro_mes_ant_20160931
Acr_maestro_mes_ant_20161030
 
I need the macro to change the date i would not have to create such a long consultation.
I did the following:
 
 
%MACRO COSECHA;
%LET DIA = ;
%DO año = 15 %TO 16;
%DO MES = 01 %TO 12;

%IF ("&MES" = 01 OR "&MES" = 03 or "&MES" = 05 OR "&MES" =07 OR "&MES" = 08 OR "&MES" = 09 OR "&MES" = 12) %THEN "&DIA" = 31;
%IF ("&MES" = 04 OR "&MES" = 06 or "&MES" = 10 OR "&MES" =11) %THEN "&DIA" = 30;

    data  prueba.Acr_maestro_"$MES$AÑO";
    set prueba.Acr_maestro_mes_ant_"&AÑO&MES&DIA";
    where LLAMADA= 1;
    keep ID LLAMADA SOLICITUD FECHA;
    %END;
 
 
I`m sure that something is missing in the query, this is the first time that i work with macros in SAS, if you can help me i would appreciate.
Sorry for my bad english.
 

Accepted Solutions
Solution
‎11-17-2016 05:47 AM
Super User
Super User
Posts: 7,401

Re: Help with macro in SAS

Hi,

 

This is and ideas area for SAS, not a place to ask questions on specific problems.  Post your question within the relevant subgroup.

As a tip, avoid putting data in dataset names (dates in this case), it will just make your coding effort far more complicated and harder to maintain, plus worse resource wise.  Secondly look at the indsname= option on a set statement, you can manipulate that (which is the dataset name from the input dataset).

View solution in original post


All Replies
Solution
‎11-17-2016 05:47 AM
Super User
Super User
Posts: 7,401

Re: Help with macro in SAS

Hi,

 

This is and ideas area for SAS, not a place to ask questions on specific problems.  Post your question within the relevant subgroup.

As a tip, avoid putting data in dataset names (dates in this case), it will just make your coding effort far more complicated and harder to maintain, plus worse resource wise.  Secondly look at the indsname= option on a set statement, you can manipulate that (which is the dataset name from the input dataset).

Super User
Posts: 5,081

Re: Help with macro in SAS

The macro language is something we can get to.  But first, should you change the objective?  You can remove the DAY from the data set name, but why switch the order?  If you keep the names as &YEAR&MONTH instead of &MONTH&YEAR, all the data set names would remain in order.  Isn't that a better result?

☑ This topic is SOLVED.

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

Discussion stats
  • 2 replies
  • 274 views
  • 2 likes
  • 3 in conversation