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

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;

 

 

 

1 ACCEPTED SOLUTION
2 REPLIES 2

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 686 views
  • 1 like
  • 2 in conversation