BookmarkSubscribeRSS Feed
pawandh
Fluorite | Level 6

I'm passing a date and it will b a character only,can't i store it in any variable or macro variable like %let or as i'm doingin code.And how can i change this date into numeric and store in a variable so that i can find no of weekdays between these two dates.


%macro ab(strt,end);

a=&strt;
b=&end;

%put a= b=;

%mend;

 

%ab(01jan2015,31jan2015);

 

5 REPLIES 5
Ksharp
Super User
%macro ab(strt,end);
a="&strt"d ;
b="&end"d ;
%put a= b=;
%mend;
pawandh
Fluorite | Level 6
it is giving error
pawandh
Fluorite | Level 6
but if i'm creating a dataset then it is working fine .

%macro ab(strt,end);
data _null_;
a="&strt"d;
b="&end"d;

put a= b=;
run;
%mend;

%ab(01jan2015,31jan2015);
JoshB
Quartz | Level 8

There's some mixing of data step and macro functionality going on in previous posts.

This would be an alternative to save those strings as dates.

 

%macro ab(strt,end);
  %let a="&strt"d;
  %let b="&end"d;
  %put a=&a. b=&b.;
%mend;
 
%ab(01jan2015,31jan2015);

At that point, you should be able to use the dates in a function such as intck

 

e.g.

 

%macro ab(strt,end);
  %let diff = %sysfunc(intck(day,"&strt."d,"&end."d));
  %put Days between = &diff.;
%mend;
 
%ab(01jan2015,31jan2015);

 

I'm assuming this is part of a larger macro, so you'll be able to use the resulting value in a variable. 

Ksharp
Super User

You want express them as macro variable ?

 

%macro ab(strt,end);
%let a=%sysfunc(inputn(&strt,date9.));
%let b=%sysfunc(inputn(&end,date9.));
%let dif=%eval(&b-&a);

%put a=&a b=&b dif=&dif;
%mend;
%ab(01jan2015,31jan2015)

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 5 replies
  • 854 views
  • 0 likes
  • 3 in conversation