BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Hedegaard
Calcite | Level 5

Hello,

I have the following piece of code, where I want the macro variable &ultimo to have a date value at the end. However, after running the code once, the value of &ulitmo is still missing, but after a second run, the value appears. My question is, what am I doing wrong with respect to making the code work doing its first run? Kind regards.

%let year = 2012;
%let month = 06;

%macro ultimodato;
     %if %eval(&month) < 9 %then %do;
           %let ultimo = 01/0%eval(&month.+1)/&year.;
     %end;
     %else %if &month = 9 %then %do;
           %let ultimo = 01/10/&year.;
     %end;
     %else %if 9 < &month and &month < 12 %then %do;
           %let ultimo = 01/%eval(&month.+1)/&year.;
     %end;
     %else %if &month = 12 %then %do;
           %let ultimo = 01/01/%eval(&year+1);
     %end;
%mend ultimodato;

%ultimodato;


data _null_;
call symput('ultimo',put(input("&ultimo",DDMMYY10.),date9.));
run;

%put &ultimo;

1 ACCEPTED SOLUTION

Accepted Solutions
Florent
Quartz | Level 8

Hi,

This is because your 'ultimo' macro-variable isn't declared as global, and it is created within the macro 'ultimodato'. By declaring it as global (%global ultimo;), you will make it available to your call symput.

Kind regards,

Florent

View solution in original post

4 REPLIES 4
Florent
Quartz | Level 8

Hi,

This is because your 'ultimo' macro-variable isn't declared as global, and it is created within the macro 'ultimodato'. By declaring it as global (%global ultimo;), you will make it available to your call symput.

Kind regards,

Florent

Hedegaard
Calcite | Level 5

Thank you. It works. Smiley Happy

Astounding
PROC Star

That's the right answer to your original question.  But you should also consider whether or not you want to write a macro for this purpose.  The DATA step already has functions that will do the work for you.  For example:

data _null_;

call symput('ultimo', put( intnx('month', mdy(&month, 1, &year), +1), date9.));

run;

Good luck.

Hedegaard
Calcite | Level 5

Astounding, I didn't know you could do that! Thanks. Smiley Happy

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