Hello
User define From date and until date.
Then all months between FROM and until are calculated and create macro parameters for each date (YYYYMM).
The I need to import all files that in their name there is date YYYMM.
The problem is that some files are not existing so I need to add condition IF file exist then import (otherwise I will get an error).
When I run the "ConditionalImport" macro I get no outputs. Why?
What is the way to solve it?
What is wrong with my code?
%let FROM_Question=1403;
%let last_Question=1812;
%let FROM_Question_date=%SYSFUNC(inputn(&FROM_Question.,YYMMN4.));
%let last_Question_date=%SYSFUNC(inputn(&last_Question.,YYMMN4.));
%let n=%SYSFUNC(intck(month,&FROM_Question_date,&last_Question_date));
%put &FROM_Question_date;
%put &last_Question_date;
%put &n;
%macro months;
%do j=0 %to &n.;
m&j.=put(intnx('month',&FROM_Question_date.,&j.),yymmn6.);
call symputx("m&j",trim(left(m&j.)));
%end;
%mend;
data _NULL;
%months;
run;
%put &n;
%put &m0;
%PUT &&m&n..;
/*import-Example for import in specific date.It is working well*/
%macro iimport;
%do j=55 %to 55;
PROC IMPORT OUT=SHEELON_a&&m&j..
DATAFILE="/Path/SHEELON_&&m&j...csv"
DBMS=csv REPLACE;
GETNAMES=YES;
DATAROW=2;
RUN;
%end;
%mend iimport;
%iimport;
/*conditonal import-I get no results!!*/
%macro ConditionalImport;
%do j=0 %to 55;
%if %sysfunc(fileexist(/Path/SHEELON_&&m&j..)) %then %do;
PROC IMPORT OUT=SHEELON_a&&m&j..
DATAFILE="/Path/SHEELON_&&m&j...csv"
DBMS=csv REPLACE;
GETNAMES=YES;
DATAROW=2;
RUN;
%end;
%end;
%mend ConditionalImport;
%ConditionalImport;
You import
/Path/SHEELON_&&m&j...csv
but test for
/Path/SHEELON_&&m&j..
in the fileexist() function
You import
/Path/SHEELON_&&m&j...csv
but test for
/Path/SHEELON_&&m&j..
in the fileexist() function
Thank you so much!!!!
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: