BookmarkSubscribeRSS Feed
scb
Obsidian | Level 7 scb
Obsidian | Level 7

In the below code, I can get 2018 for variable A and 2019 for variable B.  May I know how to get 2018/2019 for variable C? Thanks.

 

%LET RUNDATE = TODAY();

 

data  _null_;
call symput("A",put(intnx('YEAR',&RUNDATE,-1),YEAR4.));
call symput("B",put(intnx('YEAR',&RUNDATE,0),YEAR4.));
run;

 

%PUT A = &A;
%PUT B = &B;

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

Yes, bur first off, please avoid shouting code at us, and finish macro variables with a dot, use the code window, and indentations!!

data  _null_;
  a=put(intnx('year',today(),-1),year4.);
  b=put(intnx('year',today(),0),year4.);
  call symput("A",a);
  call symput("B",b);
  call symput("C",catx('/',a,b));
run;

%put A=&a.;
%put B=&b.;
%put C=&c.;

The next question is, why put the today() result in a macro variable at all, or in fact the other two data items?  Each of these elements can simply be found by querying the today() function at the appropriate moment?

 

Astounding
PROC Star

Once you have this much:

 

%LET RUNDATE = TODAY();

 

data  _null_;
call symput("A",put(intnx('YEAR',&RUNDATE,-1),YEAR4.));
run;

 

That lets you continue with:

 

%let B = %eval(&A + 1);

%let C = &A/&B;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 547 views
  • 0 likes
  • 3 in conversation