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

I want to load data by using macro but last day is different from month

 

for example, in feb last day is 31 but in april 30

 

how can i do..?

 

 

%macro dataload(year=17,month=11);

proc import out = temp;
%if &month=1 or &month=3 or &month=5 or &month=7 or &month=8 or &month=10 or &month=12 %then
datafile = "J:\&year..&month.\&20&year.&month.01-20%year.%month.31.xlsx"
%else &month= 4 or &month= 6 or &month= 9 or &month= 11 %then
datafile = "J:\&year..&month.\&20&year.&month.01-20%year.%month.30.xlsx"
%else &month=2 and &year=16 %then
datafile = "J:\&year..&month.\&20&year.&month.01-20%year.%month.29.xlsx"
%else &month=2 %then
datafile =  "J:\&year..&month.\&20&year.&month.01-20%year.%month.28.xlsx"
DBMS = XLSX replace;
sheet = "sheet1";
run;

 

 

%mend

%dataload(year=17,month=11);

%dataload(year=17,month=10);

%dataload(year=17,month=09);

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User
%macro dataload(year=17,month=11);
data _null_;
day = day(intnx('month',"20&year&month.01",0,"e"));
call symputx('day',put(day,z2.),'l');
run;
/* use &day in the rest of your macro where needed */
%mend;

View solution in original post

1 REPLY 1
Kurt_Bremser
Super User
%macro dataload(year=17,month=11);
data _null_;
day = day(intnx('month',"20&year&month.01",0,"e"));
call symputx('day',put(day,z2.),'l');
run;
/* use &day in the rest of your macro where needed */
%mend;

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 connect to databases in SAS Viya

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.

Discussion stats
  • 1 reply
  • 830 views
  • 0 likes
  • 2 in conversation