BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Brayanduran
Calcite | Level 5
 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.
 
1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

Astounding
PROC Star

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?

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 2 replies
  • 1103 views
  • 2 likes
  • 3 in conversation