data ds;
format dates date9.;
infile datalines;
input dates date9.;
datalines;
15apr2018
18apr2018
20apr2018
21apr2018
22apr2018
;
run;
data _null_;
set ds;
call symput("dates"||compress(_N_),dates);
run;
%put &dates1;
%macro tr;
%global x;
%do i=1 %to 5;
x=dates.&i;
%end;
%mend;
this code not getting.Help me this regard
Check this to add all values into a Macro
proc sql;
select PUT(dates,date9.) INTO : Dates Separated by " "
from ds;
quit;
%put &Dates;
Look at CALL EXECUTE instead then.
@rajusas wrote:
That gives all dates into one macro variable
I need to use this variable into another macro
Every date wise it has to run one by one
Check this then,
proc sql;
select PUT(dates,date9.),count(*) INTO : Dates Separated by " ",:Count
from ds;
quit;
%put &Dates &Count;
data want;
do i=1 to &Count.;
Date=SCAN("&Dates.",i," ");
output;
end;
run;
A statement like
a=20apr2018;
is not valid in open code, and not valid (illegal name on the right side) in a data step anyway.
(This is one of the 5 statements created by the macro)
Correction: since you use a numeric format in the input, you get 5 statements
a=20000;
(numbers vary).
As mentioned, such statements are not valid in open code. They would be valid in a data step.
Second correction after running that code on a SAS system:
Since you do not adress your macro variables correctly, this is the result of calling the macro:
54 %tr NOTE: Line generated by the invoked macro "TR". 54 x=dates.&i; _ 180 ERROR 180-322: Statement is not valid or it is used out of proper order. NOTE: Line generated by the invoked macro "TR". 54 x=dates.&i; _ 180 ERROR 180-322: Statement is not valid or it is used out of proper order. NOTE: Line generated by the invoked macro "TR". 54 x=dates.&i; _ 180 ERROR 180-322: Statement is not valid or it is used out of proper order. NOTE: Line generated by the invoked macro "TR". 54 x=dates.&i; _ 180 ERROR 180-322: Statement is not valid or it is used out of proper order. NOTE: Line generated by the invoked macro "TR". 54 x=dates.&i; _ 180 ERROR 180-322: Statement is not valid or it is used out of proper order.
@rajusas wrote:
data ds; format dates date9.; infile datalines; input dates date9.; datalines; 15apr2018 18apr2018 20apr2018 21apr2018 22apr2018 ; run; data _null_; set ds; call symput("dates"||compress(_N_),dates); run; %put &dates1; %macro tr; %global x; %do i=1 %to 5; x=dates.&i; %end; %mend;
@rajusas wrote:
In data it is yymmdd format
No. You never assign or otherwise use that format in your code.
data ds;
format dates date9.;
infile datalines;
input dates date9.;
datalines;
15apr2018
18apr2018
20apr2018
21apr2018
22apr2018
;
run;
%macro print_date(date=);
%put The Date is: %sysfunc(putn("&date."d, yymmddd10.));
%put The day after the date is: %sysfunc(intnx(day, "&date"d, 1, s), yymmddd10.);
%mend;
data _null_;
set ds;
str = catt('%print_date(date=',
put(dates, date9.),
');');
call execute (str);
run;
Given your original program, the simplest fix would be to change this statement:
x=dates.&i;
Turn that into:
%let x = &&dates&i;
Then immediately (don't wait until after the %DO loop, and certainly don't wait for a different macro) add the macro call that should run for each date, referring to &X as needed.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.